I want to display some floating boxes (divs containing thumbnails) and the number of thumbnails depends on the current page width. For example:
<div class="container">
<div class="box1" style="float:left;width:120px;height:120px;margin-right:10px;">Thumbnail image here</div>
<div class="box2" style="float:left;width:120px;height:120px;margin-right:10px;">Thumbnail image here</div>
<div class="box3" style="float:left;width:120px;height:120px;margin-right:10px;">Thumbnail image here</div>
<div class="box4" style="float:left;width:120px;height:120px;margin-right:10px;">Thumbnail image here</div>
.......... ETC
</div>
the problem is that for a given width it shows for example 4 boxes on each row, but they are all left aligned and there is some white space to the right, how can i center horizontally for each row??
Something like this: http://realworldstyle.com/thumbs_3.html but with boxes centered horizontally on the page…
thanks in advance,
Sorry, but will not be able to do what you are wanting with straight CSS + HTML. (Take a look at @Pekka for an alternative, though if the row of thumbnails don’t fill the whole row, they would be centered by themselves on the last row)
You would need to have a fixed width on the parent object
.containerwithmargin-left: autoandmargin-right:autowhich you cannot do since it is a fluid width page.Here is how I would go about doing it, though it is sure to have some bugs you will need to work around:
window.resizeeventdiv.containerto be that width plus the little bit of margin on the right. Thisdivwould always have amargin-leftandmargin-rightofautoThis will center the thumbnails as best as possible. Depending on your visual display, you may need an additional wrapping div to provide the
100% widthbackground.