I have a div container with display: inline-block;
with a background color.
Inside this div, I add more rectangle divs side by side with float:left
.
When there is not enough space for all the divs on one line, the next one is added under the others, leaving an empty space on the right side of the page. The empty space left over has the color of the background of my container but I want it to be white.
The image on the left is what it currently looks like. The image on the right is what it should look like; the parents background should shrink wrap around its children:
Here is a jsfiddle of the below:
.bigDiv {
background-color: #aaa;
display: inline-block;
}
.item {
height: 50px;
width: 150px;
background-color: #000;
float: left;
margin: 10px;
}
<div class="bigDiv">
<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>