+1  A: 

There is no easy way to do this that is crossbrowser friendly that I know of.

At least in firefox you can create an simulated table by setting divs with

display:table;
display:table-row;
display:table-cell;

So that those divs work like table elements. Then the box will contain it's content. Wether that's a good solution or not is debateable.

I've been having similar issues with page layouts myself. Usually I've solved those by setting min-width and overflow:auto;

Mikko Tapionlinna
I wish there was an overflow:contain; in css.
Mikko Tapionlinna
Thanks. overflow:contain is exactly what I need. Then I can stop using tables.
fcs
AFAIK there is no such value as overflow: containhttp://www.w3schools.com/Css/pr_pos_overflow.asp
Calvin
There is no such value, that's why I said that I wish there was.
Mikko Tapionlinna
display:table is not a realistic option until it is supported by IE
roryf
Rory, you're correct. That's why my first sentence said that there's no easy crossbrowser way
Mikko Tapionlinna
"Then I can stop using tables" being some time in the future...:)
fcs
Looks like you were correct from the start. "There is no easy way to do this". I'm going back to tables for this. Thanks.
fcs
A: 

One way is to make your boxes floats. Add float:left; to box, box-header, and box-body. Add clear:both; to box-body to force it below box-header. You'll probably need to add clear property to whatever content follows as well.

You will not get right edges of box-header and box-body to align, though. If you want their widths to be the same, you really want a table. Table is a tool to make all cells in the same column to share the widths.

For other ideas, check out this SO question.

buti-oxa
Thanks. I want the widths to be the same. Sounds like I need to use tables.
fcs
A: 

This works (actually holds together better than tables in ie7 too)

div.box{
  float:left;
  width:auto;
  margin: 10px 1000px 10px 10px;
}

div.box-header{
  float:left;
  width:100%;
  border:  solid  1px  #BBBBBB ;
  font-size: larger;
  padding: 4px; 
  background-color: #DDDDDD;
}

div.box-body{
  clear:left;
  float:left;
  width:100%; 
  padding: 4px; 
  border:  solid  1px  #BBBBBB ; 
  border-top: none;
}

NOTE: both boxes have to have same left and right padding or one juts out a bit.

wheresrhys
Works great in IE but not so good in Firtefox or chrome.
fcs
I tested it in Firefox and it was fine for me
wheresrhys
Just tested again, this time in chrome and safari too. You sure you copied the code correctly? coz it definitely does work.
wheresrhys
The container should not overlap AND resize with the page. When I pull it up in firefox you solved the overlap but no resize. I put up a sample here: http://www.c3o.com/wheresrhys.htm
fcs
Resizes fine in IE
fcs
Well that's just plain weird. Here is a test page I've done which works: http://wheresrhys.co.uk/resources/test.html. There must be some tiny unspottable difference between what we've got.
wheresrhys
I think your doc type is telling firefox to use quirks mode which makes it work. Is quirks mode bad? I'll change my doc type and see if I can get this to work in real life.
fcs
Good point. I've now amended the doctype...... and it still works.I've noticed one major differehce with your copy though: you have margin 10px on all sides of the box, whereas I have 1000px on one side
wheresrhys
now it breaks in ie7 - oh well, I give up
wheresrhys
A: 

Firstly, you should be using semantic markup. If something is a header and content mark it up as such with header and paragraph tags. That will help you move out of the 'table-way' of thinking were you try to emulate your markup and styles like a table, markup should come first, CSS can come after.

The following should do what you want:

<style type="text/css">
    * {
    margin:0px;
    padding:0px;
    }
.box {
border: solid 1px #BBBBBB;
margin:10px;
}
.box h3 {
padding: 4px;
border-bottom: solid 1px #BBBBBB;
background-color: #DDDDDD;
}
.box p {
padding: 6px;
}
</style>

<div class='box'>
    <h3>please help make these divs stop overlapping</h3>
    <p>please help make these divs stop overlapping</p>
</div>

Thinking about markup and style separately is the path to CSS Zen Mastery :o)

roryf
Thanks but this still allows overlaps. Nice but misses the point of the question.
fcs
Please explain what you mean by 'overlaps' then, this worked fine for me in FF3.
roryf
I added some non-breaking spaces to make it more obvious. Check out this image of firefox: http://www.c3o.com/overlap1.jpg. I just need a container that will not overlap (like a table).
fcs
A: 

Floats are not needed, but you seem to be confusing the uses of margin vs. padding. The following minor tweaks to your style works as you need it to:

<style type="text/css">
    div.box, table.box
    {
        margin: 10px 1000px 10px 10px;
        border:  solid  1px  #BBBBBB ;
       padding: 0px;
    }

    div.box-header, td.box-header
    {

        font-size: larger;
        padding: 4px;
        background-color: #DDDDDD;
    border-bottom:  solid  1px  #BBBBBB ;

    }   

    .box-body, td.box-body
    {
        padding: 6px;
    }
</style>

I've changed the padding on the box to a margin, moved the border to your box, and added an underline to the header.

Traingamer
I probably am mixing up padding and margins but you solution still has the same overlap. Just run it with a non-quirks mode doc-type.
fcs
I misunderstood the problem. I'll look at again later - only have IE at work.
Traingamer
+1  A: 

If you really don't want to use a table you can do this:

div.box div {
  overflow: hidden;
  zoom: 1; /* trigger haslayout for ie */
}

Next time this kind of problem comes up go to giveupandusetables.com.

Kristof Neirynck
Nice link. I am surprised how hard this has been. Seems like such a basic thing: "a container that always contains content".
fcs
It *is* very basic.
Traingamer
my answer is giveupandusetables.com
fcs