CSS div position gets messed up on zooming the browser - css

I'm developing a website for Facebook application which is based on grid image layout. The following code works fine for me but when i zoom my browser everything gets messed up. browser with 100% zoom view works. please help me to find some other code if possible or fix the following code.
<style>
div.img {
margin: 5px;
padding: 5px;
border: 1px solid #0000ff;
height: auto;
width: auto;
float: left;
text-align: center;
}
div.img img {
display: inline;
margin: 5px;
border: 1px solid #ffffff;
}
div.img a:hover img {
border: 1px solid #0000ff;
}
div.desc {
text-align: center;
font-weight: normal;
width: 120px;
margin: 5px;
}
</style>
HTML:
<div class="img">
<a target="_blank" href="klematis_big.htm"><img src="image1.jpg" alt="PHOTO" width="110" height="90"></a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="img">
<a target="_blank" href="klematis2_big.htm"><img src="image2.jpg" alt="PHOTO" width="110" height="90"></a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="img">
<a target="_blank" href="klematis3_big.htm"><img src="image3.jpg" alt="PHOTO" width="110" height="90"></a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="img">
<a target="_blank" href="klematis4_big.htm"><img src="image4.jpg" alt="PHOTO" width="110" height="90"></a>
<div class="desc">Add a description of the image here</div>
</div>

I updated the fiddle of Sdghasemi. Added fallback for older browsers without width calculation function and set the image width to 100% and cleaned up the Html a little (closing image tags etc)
The reason that images where flowing out of the container div was the width and height attributes in the HTML. I set it now to 100% of the container. Meaning 100% -2px because of the border. Same with the image caption.
<div class="img">
<a target="_blank" href="klematis_big.htm">
<img src="http://lorempixel.com/110/90/" alt="PHOTO"/>
</a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="img">
<a target="_blank" href="klematis2_big.htm">
<img src="http://lorempixel.com/110/90/" alt="PHOTO"/>
</a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="img">
<a target="_blank" href="klematis3_big.htm">
<img src="http://lorempixel.com/110/90/" alt="PHOTO"/>
</a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="img">
<a target="_blank" href="klematis4_big.htm">
<img src="http://lorempixel.com/110/90/" alt="PHOTO"/>
</a>
<div class="desc">Add a description of the image here</div>
</div>
css:
div.img {
margin: 5px;
padding: 5px;
border: 1px solid #0000ff;
height: auto;
width: 24%;
width: calc(25% - 22px);
float: left;
display: block;
overflow: hidden;
text-align: center;
font-size: 100%;
}
div.img a:hover img {
border: 1px solid #0000ff;
}
div.img img{
width: 99%;
width: calc(100% - 2px);
border: 1px solid #fff;
}
div.desc {
text-align: center;
font-weight: normal;
width: 100%;
width: calc(100% - 10px);
margin: 5px;
}
http://jsfiddle.net/or2ua75e/5/

In this case you have to use CSS's calc() function to calculate the right width of every image on page resize or zoom:
width: calc(24.9% - 22px);
the reason i used 22px: 2 * (margin + border.width + padding) for every image.
and use 24.9% instead of 25 for sure.
See working FIDDLE here

Related

Image gallery block with CSS with different image dimension?

I was trying to achieve the below layout with CSS. Here is the layout snap:
https://archive.org/details/Untitled1_20161122
Without masonry as this is not possible with masonry I guess (row/column width/height both changes which is not the case in masonry, I might be wrong though). Is there a nice pure CSS solution. It would be much appreciated. I have been searching for a CSS solution for quite long. www.bata.com for example have similar result in their homepage if that helps to explain the purpose, and without masonry as far as I am concerned.
Here is my code:
.gallery {
width: 70%;
margin: 0 auto;
background: crimson;
position: relative;
}
.col-20 {
width: 20%;
float: left;
/*border: 1px solid red;*/
}
.col-40 {
width: 40%;
float: left;
/*border: 1px solid red;*/
}
.col-60 {
width: 60%;
float: left;
/*border: 1px solid red;*/
}
div {
overflow: hidden;
}
img {
width: 100%;
height: auto;
}
<div class="gallery">
<div class="col-40">
<img src="1.png" alt="">
</div>
<div class="col-20">
<img src="2.jpg" alt="">
</div>
<div class="col-20">
<img src="3.jpg" alt="">
</div>
<div class="col-20">
<img src="4.png" alt="">
</div>
<div class="col-20">
<img src="2.jpg" alt="">
</div>
<div class="col-20">
<img src="3.jpg" alt="">
</div>
</div>
Thank you in advance.
If you are fine with a static layout, you could use a table with a fixed layout and no borders.
https://css-tricks.com/fixing-tables-long-strings/
Set your images as backgrounds for the table with background-size: cover;
Then using width, colspan and rowspan, create a fixed layout on your table.

Not able to set bottom Div just below the adjacent top Div

h1,h2,h3,h4,h5,h6 {
font-size: 100%;
}
<!--top Div-->
<div style="width: 100%; height:100%;background-color: orange">
<div style="width: 80%; height:20%;color: navy; background-color: yellow; solid blue;text-align:right;align:center;margin: 0 auto;">
<div style="width: 20%; height:80%;color: navy; background-color: pink; border: 1px black; padding: 5px;float:right">
<h2> <p style="text-align:right;">Enter Site Title</p> </h2>
<h1> <p style="text-align:right;">Enter Site Slogen</p> </h1>
</div>
</div>
<!-- top Div Close -->
<div style="width: 80%; height:80%;color: navy; background-color: pink; solid blue;text-align:right;align:center;margin: 0 auto">
<div style="width: 100%; height:85%;background-color: green;position: relative;">
<div style="width: 30%; height:100%;color: navy; background-color: blue; solid blue;text-align:right;align:left;float: left">
<h1 style="text-align:right;" style="margin-right: 20px">Enter Site Title</h1>
<h2 style="text-align:right">Enter Site Slogen</h2>
</div>
<div style="width: 65%; height:100%;color: navy; background-color: cyan; solid blue;text-align:right;align:left;float: right;">
<h1 style="text-align:right;margin-right: 20px;">Enter Site Title</h1>
<h2 style="text-align:right">Enter Site Slogen</h2>
</div>
</div>
<div style="width:100%;height:15%;background-color: red;position: top;clear: both">
<p style="text-align:right;font-size:15px;">Enter Site Title</p>
</div>
</div>
</div>
You can see red Div get little out of parent div and also little space between blue Div and Red Div.
You are trying to make a footer.
To make a footer snatch to the bottom.
Instead of typing inline CSS, make a CSS file and call it in the HTML page by writing:
<head>
<link rel="stylesheet" href="styles.css">
</head>
In the <head> section.
In the HTML div, write:
<div id="footer"> Footer text here </div>
In the CSS file, write:
#footer {
clear: both;
position: relative;
z-index: 10;
height: 3em;
margin-top: -3em;
}
It should stay at the bottom. :)

How to fix that Firefox renders Bootstrap Thumbnail differently than Google Chrome?

Why does the latest Firefox browser render Bootstrap thumbnails differently than Google Chrome? I stuck with getting all thumbnails equal height but can't figure out how.
Setting the max-width attribute to none fixes the height, but lets the image overflow its parent container. Can you tell me why and how to fix so that it appears in all Browsers like it appears in Google Chrome?
Here is my fiddle.
EDIT: added screenshots (right-click -> 'open in new tab' to see fullsize)
Chrome: max-width = 100% (default) - fitting nicely
Chrome: max-width = none - overflowing parent
Firefox: max-width = 100% (default) - downscaled by BS
Firefox: max-width = none - overflowing parent
If your images height is fixed to 240px, than one of the solutions is to wrap them in absolute positioned span and use this css:
.thumbnails {
margin: 0 0 10px 0;
padding: 0;
}
.thumbnail {
position: relative;
height: 250px;
}
.thumbnail span {
margin: 0 auto;
display: block;
position: absolute;
top: 4px;
left: 4px;
right: 4px;
bottom: 4px;
overflow: hidden;
}
.thumbnail span img {
margin: 0 auto;
display: block;
}
Check it in this Fiddle, or run the snippet below:
.thumbnails {
margin: 0 0 10px 0;
padding: 0;
}
.thumbnail {
position: relative;
height: 250px;
}
.thumbnail span {
margin: 0 auto;
display: block;
position: absolute;
top: 4px;
left: 4px;
right: 4px;
bottom: 4px;
overflow: hidden;
}
.thumbnail span img {
margin: 0 auto;
display: block;
}
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="panel panel-default">
<div class="panel-body">
<div id="slideshow">
<div>
<div>
<div data-index="1">
<ul class="thumbnails list-unstyled">
<li class="slide col-xs-4">
<a href="#" class="thumbnail" title="This is ok">
<span>
<img src="http://i.imgur.com/DONm5Ih.jpg" class="shot landscape" width="auto" height="auto" alt="image" />
</span>
</a>
</li>
<li class="slide col-xs-4">
<a href="#" class="thumbnail" title="This is ok">
<span>
<img src="http://i.imgur.com/TFEAQTJ.jpg" class="shot portrait" width="auto" height="auto" alt="image" />
</span>
</a>
</li>
<li class="slide col-xs-4">
<a href="#" class="thumbnail" title="This is ok">
<span>
<img src="http://i.imgur.com/WZbs0wI.jpg" class="shot landscape" width="auto" height="auto" alt="image" />
</span>
</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

Create 6 boxes with css

I really need some help with some easy css that I just can't get my head around.
I want to create boxes like in the link below.
I guess I could have the code for just one of them, and then use it over and over again, but how do I create the boxes so that they don't mind the other stuff around them?
Example here: http://s23.postimg.org/qypbfvv0r/boxes.jpg
Here: I have figured out a way of doing this. I hope that this helps you in some way in helping you figure out how to finish your task.
HTML:
<div class="containers">
<p class="heading">Heading</p>
<div class="inner1"></div>
<div class="inner2"></div>
</div>
<div class="containers">
<p class="heading">Heading</p>
<div class="inner1"></div>
<div class="inner2"></div>
</div>
<div class="containers">
<p class="heading">Heading</p>
<div class="inner1"></div>
<div class="inner2"></div>
</div>
CSS:
.containers {
width: 300px;
height: 150px;
border: 1px solid black;
margin-bottom: 10px;
overflow: hidden;
position: relative;
}
.inner1 {
margin-left: 5px;
width: 135px;
height: 80px;
border: 1px solid black;
background-color: blue;
}
.inner2 {
position: relative;
float: right;
top: -60%;
margin-left: 5px;
margin-right: 5px;
width: 135px;
height: 80px;
border: 1px solid black;
background-color: red;
}
.heading {
padding-left: 20px;
}
You can start off using this code. After this you can give border styles and colors to the individual divs.
<div>
<div style="float:right"> Content </div>
<div style="float:left"> Content </div>
</div>
<div style="padding-top:10px">
<div style="float:right"> Content </div>
<div style="float:left"> Content </div>
</div>
<div style="padding-top:10px">
<div style="float:right"> Content </div>
<div style="float:left"> Content </div>
</div>
Hope this helps

How to Align Vertically the image in a div?

How to display the image as vertical align in div container?
The image "setting.png" placed in last column in the code i attached. please advice solution please.
.table{
width: 100%;
margin: 20px 0px 20px 0px;
background-color: #EEEEEE;
}
.tableRow{
width: 100%;
clear: both;
height: 40px;
line-height: 40px;
border-bottom: 1px solid #cccccc;
}
.tableCol{
float: left;
height: 40px;
line-height: 40px;
}
<div class="table">
<div class="tableRow">
<div class="tableCol" style="width:10%; text-align:center;">1</div>
<div class="tableCol" style="width:40%">Michael</div>
<div class="tableCol" style="width:40%">webexp#gmail.com</div>
<div class="tableCol" style="width:10%;">
<a href="" ><img src="images/icons/setting.png" alt="Setting" align="absmiddle" /></a>
</div>
</div>
</div>
Just add (space before a link)
<div class="table">
<div class="tableRow">
<div class="tableCol" style="width:10%; text-align:center;">1</div>
<div class="tableCol" style="width:40%">Michael</div>
<div class="tableCol" style="width:40%">webexp#gmail.com</div>
<div class="tableCol" style="width:10%;">
<a href="" ><img src="images/icons/setting.png" alt="Setting" align="absmiddle" /></a>
</div>
</div>
</div>
better solution:
add this to css:
img {
margin-top:10px;
}
Here, this should work:
Add this to your div which contains the image that should be centered.
display:table-cell;
vertical-align:middle;
This should center the image vertically no matter the dimensions of your div or the image that it contains.
You can do this with position: absolute; if you know the dimensions of the settings.png image (20px x 20px for this example).
Add class tableColSettings to the <a> around the settings image. Then add CSS;
.tableColSettings{
position: absolute;
display: block;
top: 50%;
left: 50%;
margin: -10px 0 0 -10px; /* Half image dimensions */
width: 20px;
height: 20px;
line-height: 0;
}
.tableColSettings img{
width: 100%;
}
The settings image will always stay in the center of the element, no matter the height. Here's a working fiddle: http://jsfiddle.net/384pa/
Hope this helps!
Css is having a tag name
"vertical-align" may be you will get your solution

Resources