I have a fluid width container DIV.
Within this I have 4 DIVs all 300px x 250px…
<div id="container">
<div class="box1"> </div>
<div class="box2"> </div>
<div class="box3"> </div>
<div class="box4"> </div>
</div>
What I want to happen is box 1 to be floated left, box 4 to be floated right and box 2 and 3 to be spaced evenly between them. I want the spacing to be fluid as well so as the browser is made smaller the space becomes smaller also.

See: http://jsfiddle.net/thirtydot/EDp8R/
text-align: justifycombined with.stretchis what’s handling the positioning.display:inline-block; *display:inline; zoom:1fixesinline-blockfor IE6/7, see here.font-size: 0; line-height: 0fixes a minor issue in IE6.The extra
span(.stretch) can be replaced with:after.This still works in all the same browsers as the above solution.
:afterdoesn’t work in IE6/7, but they’re usingdistribute-all-linesanyway, so it doesn’t matter.See: http://jsfiddle.net/thirtydot/EDp8R/3/
There’s a minor downside to
:after: to make the last row work perfectly in Safari, you have to be careful with the whitespace in the HTML.Specifically, this doesn’t work:
And this does:
You can use this for any arbitrary number of child
divs without adding aboxNclass to each one by changingto
This selects any div that is the first child of the
#containerdiv, and no others below it. To generalize the background colors, you can use the CSS3 nth-order selector, although it’s only supported in IE9+ and other modern browsers:becomes:
See here for a jsfiddle example.