I have a container of tiles (or divs) and I want the container to be centered, while the tiles are left justified in the container.
so if the window is small:
<
Answer the same like Danield's, but in SCSS:
*
{
margin:0;padding:0;
}
$item-width:200px;
$item-height:100px;
$margin: 15px;
$min-cols:2;
$max-cols:6; //set an upper limit of how may columns you want
//to write the media queries forss to css
@for $i from $min-cols to $max-cols + 1 {
$index-width: $i*$item-width;
@media (min-width:$index-width) {
#content {
width: $index-width;
}
}
}
#content {
margin:0 auto;
overflow: auto;
min-width: $min-cols * $item-width;
max-width: $max-cols * $item-width;
display: block;
list-style:none;
background: aqua;
}
.box {
float: left;
height: $item-height - 2 *$margin;
width: $item-width - 2*$margin;
margin:$margin;
background-color:blue;
}
It generates the same CSS like his solution.
Working codepen example here.