css - Center float boxes horizontally -
I want to display some floating boxes (thumbnails containing divs) and the number of thumbnails depends on the current page width. For example:
& lt; Div class = "container" & gt; & Lt; Div square = "box 1" style = "float: left; width: 120px; height: 120px; margin-right: 10px;" & Gt; Thumbnail image here & lt; / Div & gt; & Lt; Div square = "box 2" style = "float: left; width: 120px; height: 120px; margin-right: 10px;" & Gt; Thumbnail image here & lt; / Div & gt; & Lt; Div class = "box3" style = "float: left; width: 120px; height: 120px; margin-right: 10px;" & Gt; Thumbnail image here & lt; / Div & gt; & Lt; Div square = "box 4" style = "float: left; width: 120px; height: 120px; margin-right: 10px;" & Gt; Thumbnail image here & lt; / Div & gt; .......... ETC & lt; / Div & gt;
The problem is that 4 boxes are shown for example in each row for the given width, but these are all left-hand combinations and some white space on the right, I can see horizontally How can I do the center
Something like this: But horizontally centered on the page with boxes ...
Thanks in advance,
Sorry, but directly with CSS + HTML, whatever you want They are not able to do it (take a look at Pekka for one option, however, if the thumbnail line does not fill the entire row, they will be centered on the last line)
You have a definite criteria- Left: Auto- and margin-right: Auto
with the parent object .container
on the width that you can do because the page is a liquid width.
Here is how I would like to go about doing this, although there are some bugs to ensure that you will need to work around:
- A javascript event Bind to
window.resize
event - Get new document widths and see how many thumbnails fit in a row
- set width of the div Container along with that width is a small margin on the right side Always
margin-left
andmargin-right
will be
automatically
indiv
This will centrestage the thumbnail as best as possible. Depending on your visual display, you may need an additional wrapping device to provide a
100% width
background.