However, the way the container (outside div) border is rendered varies between browsers: In IE7 and Op10 the borders go all around the three inner divs as expected but for Chrome/FF the inner divs seem to float below the container somehow.
Also, is it essential to use a div height because I’m not sure how much content will be inside each div?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
.container {
float:left;
border:1px solid #000;
border-top:none;
margin:20px;
clear:both;
}
.inner {
float:left;
}
.box {
float:left;
width:200px;
clear:left;
border-right:1px solid #000;
border-top:1px solid #000;
margin:0 -1px 0 0;
position:relative;
}
.box2 {
width:200px;
clear:none;
border-left:1px solid #000;
margin:0 -1px 0 0;
}
</style>
</head>
<body>
<div class="container" >
<div class="inner">
<div class="div1 box">
<p>Some text in div1 : Some text in div1 : Some text in div1 : Some text in div1 : </p>
</div>
<div class="div2 box">
<p>Some text in div2 : Some text in div2 : Some text in div2 : Some text in div2 : </p>
<p>Some text in div2 : Some text in div2 : Some text in div2 : Some text in div2 : </p>
</div>
</div>
<div class="div3 box box2">
<p>Some text in div3 : Some text in div3 : Some text in div3 : Some text in div3 : </p>
<p>Some text in div3 : Some text in div3 : Some text in div3 : Some text in div3 : </p>
<p>Some text in div3 : Some text in div3 : Some text in div3 : Some text in div3 : </p>
</div>
</div>
<div class="container" >
<div class="inner">
<div class="div1 box">
<p>Some text in div1 : Some text in div1 : Some text in div1 : Some text in div1 : </p>
</div>
<div class="div2 box">
<p>Some text in div2 : Some text in div2 : Some text in div2 : Some text in div2 : </p>
<p>Some text in div2 : Some text in div2 : Some text in div2 : Some text in div2 : </p>
</div>
</div>
<div class="div3 box box2">
<p>Some text in div3 : Some text in div3 : Some text in div3 : Some text in div3 : </p>
<p>Some text in div3 : Some text in div3 : Some text in div3 : Some text in div3 : </p>
<p>Some text in div3 : Some text in div3 : Some text in div3 : Some text in div3 : </p>
<p>Some text in div3 : Some text in div3 : Some text in div3 : Some text in div3 : </p>
<p>Some text in div3 : Some text in div3 : Some text in div3 : Some text in div3 : </p>
<p>Some text in div3 : Some text in div3 : Some text in div3 : Some text in div3 : </p>
</div>
</div>
<div class="container" >
<div class="inner">
<div class="div1 box">
<p>Some text in div1 : Some text in div1 : Some text in div1 : Some text in div1 : </p>
<p>Some text in div1 : Some text in div1 : Some text in div1 : Some text in div1 : </p>
<p>Some text in div1 : Some text in div1 : Some text in div1 : Some text in div1 : </p>
<p>Some text in div1 : Some text in div1 : Some text in div1 : Some text in div1 : </p>
<p>Some text in div1 : Some text in div1 : Some text in div1 : Some text in div1 : </p>
<p>Some text in div1 : Some text in div1 : Some text in div1 : Some text in div1 : </p>
<p>Some text in div1 : Some text in div1 : Some text in div1 : Some text in div1 : </p>
<p>Some text in div1 : Some text in div1 : Some text in div1 : Some text in div1 : </p>
<p>Some text in div1 : Some text in div1 : Some text in div1 : Some text in div1 : </p>
<p>Some text in div1 : Some text in div1 : Some text in div1 : Some text in div1 : </p>
<p>Some text in div1 : Some text in div1 : Some text in div1 : Some text in div1 : </p>
</div>
<div class="div2 box">
<p>Some text in div2 : Some text in div2 : Some text in div2 : Some text in div2 : </p>
<p>Some text in div2 : Some text in div2 : Some text in div2 : Some text in div2 : </p>
</div>
</div>
<div class="div3 box box2">
<p>Some text in div3 : Some text in div3 : Some text in div3 : Some text in div3 : </p>
</div>
</div>
</body>
</html>
However it would be much easier using a table and if you want to copy exact table behaviour then I would say use a table until IE7 is dead and you can use display:table instead.
The issue is probably why you need something like and perhaps a design change would simplify things so that you don’t need tricks like this
Well it can be done without the inner but needs hacks for iE6.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
.container {
float:left;
border:1px solid #000;
border-top:none;
margin:20px;
clear:both;
}
.inner {
float:left;
}
.box {
float:left;
width:198px;
clear:left;
border-top:1px solid #000;
border-right:1px solid #000;
margin:0 -1px 0 0;
position:relative;
padding:1px;
}
* html .box{margin-right:-4px;}
.box2 {
width:198px;
float:none;
clear:none;
border-left:1px solid #000;
border-right:none;
margin:0 0 0 200px;
}
* html .box2{margin-left:197px}
</style>
</head>
<body>
<div class="container" >
<div class="div1 box">
<p>Some text in div1 : Some text in div1 : Some text in div1 : Some text in div1 : </p>
</div>
<div class="div2 box">
<p>Some text in div2 : Some text in div2 : Some text in div2 : Some text in div2 : </p>
<p>Some text in div2 : Some text in div2 : Some text in div2 : Some text in div2 : </p>
</div>
<div class="div3 box box2">
<p>Some text in div3 : Some text in div3 : Some text in div3 : Some text in div3 : </p>
<p>Some text in div3 : Some text in div3 : Some text in div3 : Some text in div3 : </p>
<p>Some text in div3 : Some text in div3 : Some text in div3 : Some text in div3 : </p>
</div>
</div>
<div class="container" >
<div class="div1 box">
<p>Some text in div1 : Some text in div1 : Some text in div1 : Some text in div1 : </p>
</div>
<div class="div2 box">
<p>Some text in div2 : Some text in div2 : Some text in div2 : Some text in div2 : </p>
<p>Some text in div2 : Some text in div2 : Some text in div2 : Some text in div2 : </p>
</div>
<div class="div3 box box2">
<p>Some text in div3 : Some text in div3 : Some text in div3 : Some text in div3 : </p>
<p>Some text in div3 : Some text in div3 : Some text in div3 : Some text in div3 : </p>
<p>Some text in div3 : Some text in div3 : Some text in div3 : Some text in div3 : </p>
<p>Some text in div3 : Some text in div3 : Some text in div3 : Some text in div3 : </p>
<p>Some text in div3 : Some text in div3 : Some text in div3 : Some text in div3 : </p>
<p>Some text in div3 : Some text in div3 : Some text in div3 : Some text in div3 : </p>
</div>
</div>
<div class="container" >
<div class="div1 box">
<p>Some text in div1 : Some text in div1 : Some text in div1 : Some text in div1 : </p>
<p>Some text in div1 : Some text in div1 : Some text in div1 : Some text in div1 : </p>
<p>Some text in div1 : Some text in div1 : Some text in div1 : Some text in div1 : </p>
<p>Some text in div1 : Some text in div1 : Some text in div1 : Some text in div1 : </p>
<p>Some text in div1 : Some text in div1 : Some text in div1 : Some text in div1 : </p>
<p>Some text in div1 : Some text in div1 : Some text in div1 : Some text in div1 : </p>
<p>Some text in div1 : Some text in div1 : Some text in div1 : Some text in div1 : </p>
<p>Some text in div1 : Some text in div1 : Some text in div1 : Some text in div1 : </p>
<p>Some text in div1 : Some text in div1 : Some text in div1 : Some text in div1 : </p>
<p>Some text in div1 : Some text in div1 : Some text in div1 : Some text in div1 : </p>
<p>Some text in div1 : Some text in div1 : Some text in div1 : Some text in div1 : </p>
</div>
<div class="div2 box">
<p>Some text in div2 : Some text in div2 : Some text in div2 : Some text in div2 : </p>
<p>Some text in div2 : Some text in div2 : Some text in div2 : Some text in div2 : </p>
</div>
<div class="div3 box box2">
<p>Some text in div3 : Some text in div3 : Some text in div3 : Some text in div3 : </p>
</div>
</div>
</body>
</html>