Now I have put float:left on my green divs but that makes them stick to the left (makes sense). Now how can I keep my divs centered while I resize the blue container?
As in this image:

Blue: Parent container Green: Divs
You can use display: inline-block on your child items and text-align: center on parent item
<div class="container">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
.container {
background-color: blue;
width:500px;
text-align: center;
}
.item {
display: inline-block;
background-color: green;
width: 100px;
height: 100px;
}
https://jsfiddle.net/g3vp2fyf/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With