Forum Moderators: open
P.S. using float is not an option because the divs will wrap. I don't want wrapping.
Also, using Position will be tedious and will make rearranging things a pain.
¦ div ¦¦ div ¦¦ div ¦<-edge of window or container, so WRAP
¦ div ¦¦ div ¦
?
Divs "inline," but allow them to wrap when they reach the edge of the page/container, is this correct? Or you mean, text inside the divs needs to wrap?
In either case, float still seems like a viable solution. Remember that a floated element will contain all its floated children. So something like this should work:
#mycontainer { width: 75%; float: left; border: 1px solid #ff0000; }
.column { width: 175px; float: left; border: 1px solid #00ff00; }
.column p { padding: 6px; margin:0; float: left; }
<div id="mycontainer">
<div class="column">
<p> Some content that may or may not wrap</p>
</div>
<div class="column">
<p> Some content that may or may not wrap</p>
</div>
<div class="column">
<p> Some content that may or may not wrap</p>
</div>
<div class="column">
<p> Some content that may or may not wrap</p>
</div>
<div class="column">
<p> Some content that may or may not wrap</p>
</div>
<div class="column">
<p> Some content that may or may not wrap/</p>
</div>
</div>
The borders are just to show you where it breaks and the "shrink wrap" effect of floats within floats doing exactly what you need. :-) Tested in FF with 4.01 valid doctype.
You may have some trouble if the divs are of varying height due to different line lengths in the p. If this is the case, you'll need another "row" wrapper around the rows, or a clearing div between rows.
<html>
<body>
<table width="550" align="center">
<tr>
<td width="250">
<div style="background: #CCCCCC; width:250px; height: 250px;">
<p>This content is appearing on top of this gray box</p>
</div>
</td>
<td width="50"> </td>
<td width="250">
<div style="background: #00CC00; width: 250px; height: 250px;">
<p>This content is appearing on top of this green box</p>
</div>
</td>
</tr>
</table>
</body>
</html>
<table width="550">
There you go! :-) Set a fixed/calculated width on #mycontainer in the example above. This will achieve the same effect.
#mycontainer { width: 532px; float: left; border: 1px solid #ff0000; }
You will find some cross-browser differences in the maths due to different handling of the box model - if you zero out all containers with margin:0;padding:0; it will help, but you may find you'll still need to make #mycontainer a little larger than the sum of all columns (even with borders off.)
My example uses fixed pixel widths on the "column divs", but you can also use percentage or em for #mycontainer with a min-width property to keep it from squashing up too far when the window is resized. The problem here is IE 6 doesn't know min-width . . . so some workarounds may be required. But it looks like your scenario will work with a fixed width.
EDIT: after a closer look at your example, you don't even need the "column" divs - look how neat and compact this is. Also note you'll have to fiddle with the widths and padding to suit your needs:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- doctype all on one line -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Floating Fixed Divs</title>
<style type="text/css">
#mycontainer { width: 538px; float: left; border: 1px solid #ff0000; }
#mycontainer p {
width: 165px;
float: left;
background: #00CC00;
padding: 6px;
margin:0;
border: 1px solid #00ff00;
}
</style>
</head>
<body>
<div id="mycontainer">
<p> Some content that may or may not wrap</p>
<p> Some content that may or may not wrap</p>
<p> Some content that may or may not wrap</p>
<p> Some content that may or may not wrap</p>
<p> Some content that may or may not wrap</p>
<p> Some content that may or may not wrap</p>
</div>
</body>
</html>