I have a really simple list. I even used a off the shelf script to make this work.
Now all of the sudden my second row floats right even though it’s told to float left. The 3rd row lines up perfect but it shouldn’t be the 3rd row. If I make the width any less than 600px it only shows 2 per line.
I want to be able to just specify a width of the gallery so that 3 images show per line.
Here is the CSS I’m using.
ul{
margin: 0 auto;
padding: 0;
}
/* The wider the #list_wrapper is, the more columns will fit in it */
#list_wrapper{
width: 600px;
float:left;
}
/* The wider this li is, the fewer columns there will be */
ul.multiple_columns li{
text-align: left;
float: left;
list-style: none;
width: 200px;
}
The problem is that the second image (images/gallery_main/bathroom.png) is a little bit (1px) higher than the other images.
This causes the <li> it’s in to be 1px higher than the <li> to it’s left and the <li> to it’s right. Since the <li>'s have float left, they will float against the nearest thing they can float against that also has float left, or the left of it’s parent if there is no such element.
If the images all have the same height there is nothing it can float against so it will start again on a new row from the left, BUT in your case it can float against the 1px the second <li> is too tall.
So:
Hope that makes sense?
There are several fixes. In order of how complex they are:
Make sure all images have the exact same height
Set a height on the <li>'s with overflow: hidden so they are guaranteed to have the same height
Use display: inline-block instead of float: left (harder to get to work in IE6 and IE7, but if you don’t care about those it’s easy).
Expanding on what Scallio said… you can do this by setting the .multiple_columns LI IMG height in the CSS, the width will be automatically adjusted. It should for the most part it should solve your issue.