The "tiles" (white boxes) that you see in image 1 are responsive to the users screen. If the screen size just isn't big enough, it leaves a gap on the right hand side. What I want to do is achieve the result as seen in image 2. Here is my code so far for those specific elements..
HTML:
<div class="main">
<div class="inner">
<div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div><div class="tile"></div>
</div>
</div>
CSS:
.main{
width:100%;
background: #000;
}
.main .inner{
margin:10px;
min-width: 140px;
background: red;
}
.main .inner .tile{
margin:10px;
height: 120px;
width: 120px;
background: #fff;
display: inline-block;
}
IMAGE 1:
IMAGE 2:
You can do this with media queries to set the width of the
.inner
class at various browser widths, then set themargin-left
andmargin-right
properties toauto
to center it. Set thepadding-top
andpadding-bottom
properties of the.main
class instead of setting top and bottom margins on the.inner
class. Use a combination ofpadding
on the.inner
class andborder
on the.tile
class to space the tiles out evenly10px
apart.For a detailed description of media queries: CSS media queries
example
css
Set a media query for each browser width, in this example I have only gone up to 800px, but you can add as many more as you need.
css (continued)
The media queries are used to set the width of
.inner
to a multiple of130px
which is the width of a.tile
with a border of10px
.If you want to change the spacing between the tiles you would need to alter the
border
on the.tile
class, thepadding
on the.inner
class, themargin-top
andmargin-bottom
on the.main
class and thewidth
that is specified in each of the media queries.Add text-align:center css property http://jsfiddle.net/dolours/afKgg/
You could set max-width for
.inner
then havetext-align: center
for.main