So I have three divs and I would like all three of them to take up the full width of their container and have a specific margin between them.
<div class="container">
<div class="foo">
content
</div>
<div class="foo">
bit more content
</div>
<div class="foo>
Very much more content
</div>
</div>
And my CSS looks something like:
.foo {
width: 31%;
margin-left: 10px;
}
.foo:first-child {
margin-left: 0px;
}
However, with this set up the divs will wrap when the page gets too small and the divs will not stretch to the edge when the page is too big.
Is there an easy way to have a CONSTANT margin between them (no 'margin-left: 3%') yet still have the three divs stretch evenly across no matter the size of the page?
EDIT From the first answer, I took the idea of putting the padding inside of the div making it accounted for as part of the width and modified it a bit to use css that is more fully supported across all browsers.
So as long as the container of the three divs remains greater than 120px, the spacing between the divs in this example will always be a constant 16px. Also, no matter the size of the outer container, the inside divs will always take up the entire width of the three containers.
Example: http://jsfiddle.net/U8U7D/5/