I have a bunch of boxes filled with content. The number of boxes in each row varies depending on the width of the browser window.
Is there a way to ensure that all the boxes are always horizontally centered on the page?
For guidance, you can check out this example: FIDDLE
HTML:
<body>
<div class="centered">
<div class="segment">Content</div>
<div class="segment">Content</div>
<div class="segment">Content</div>
<div class="segment">Content</div>
<div class="segment">Content</div>
<div class="segment"><Content</div>
<div class="segment">Content</div>
<div class="segment">Content</div>
<div class="segment">Content</div>
<div class="segment">Content</div>
<div class="segment">Content</div>
</div>
</body>
CSS:
body {
background-color:grey;
margin:0px;
padding:0px;
}
.centered {
min-width:620px;
max-width:1920px;
margin-right:auto;
margin-left:auto;
}
.segment {
float:left;
height:300px;
width:300px;
margin:5px;
background-color:red;
}
I'm willing to consider JavaScript and jQuery solutions, but I'd prefer to utilize HTML and CSS if possible.