I have the following setup, but setting the width of the divs to a something around 30% is not working consistently (once the window width goes less than some number the third divs drops below..
Is there a better way of doing this, so that my divs always stay inline and keep getting smaller and smaller while the margin stays fixed at 18px between them ?
CSS :
.parent {
width: 100%;
height: 50px;
}
.child {
float: left;
margin-right: 18px;
border: 2px solid white;
text-align: center;
line-height: 50px;
height: 100%;
width: ~30%; /* doesn't work */
}
.child:nth-child(3) {
margin-right: 0;
}
HTML :
<div class="parent">
<div class="child">one</div>
<div class="child">two</div>
<div class="child">three</div>
</div>
If you are looking for IE8 support, and can change your markup, you can nest the blocks inside 33.33% width elements.
For IE8 support, you need to get rid of the
nth-child()
declaration. In order to have inner gaps only, I used the technique described here : Items grid with inner padding only.DEMO
Use
calc()
to calculate column width.Calc
is supported since IE9.