I'm trying to create four gray squares that display in the middle of the browser.
Each square is set to be 40 pixels wide and have borders of 10 pixels.
I use the box_container
class in a <div>
to allow some CSS to center the four boxes.
If I set the width of the box_container
class to 240px
, only 3 boxes fit into the first row.
I need to set the width to 250px
minimum to get all the four boxes to display in one row. Why is this when the eight borders of 10px and four img boxes of 40px adds up to 240px (10px*8 + 40px*40 = 240px)?
<style type="text/css">
.boxes {
height: 40px;
width: 40px;
background-color: gray;
margin: 10px 10px 10px 10px;
}
.box_container {
width: 250px;
margin: 0 auto;
}
</style>
<div class="box_container">
<img class="boxes"></img>
<img class="boxes"></img>
<img class="boxes"></img>
<img class="boxes"></img>
</div>