Forum Moderators: not2easy
+-- Container ------------------+
¦+-- float1 ---+ +-- float2 ---+¦
¦¦ width = 50% ¦ ¦ width = 50% ¦¦
¦+-------------+ +-------------+¦
+-------------------------------+
Container contains a bunch of stuff before and after the floats, and I can't float Container. Container also has some padding. float1 and float2 are both fieldsets.
The problem I have is that because container has padding, if I set the widths on the float to be 50%, then they will be too large because the width doesn't account for the padding. Any ideas how I might do this?
The table-layout approach would be a table with a width of 100%, 1 row, 2 columns, each column with a width of 50%.
Thanks.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset:utf-8">
<title>Test</title>
<style type="text/css">
body { margin: 0; padding: 0; }
#container { border: 1px solid blue; }
#boxA { float: left; width: 50%; padding: 5px; background-color: #fee; border: 2px solid black; }
#boxB { float: left; width: 50%; padding: 5px; background-color: #efe; border: 2px solid black; }
</style>
</head>
<body>
<div id="container">
<div id="boxA">BLah blah blah</div>
<div id="boxB">Blah blah blah</div>
</div>
</body>
</html>
For each floated div with its dictated 50% width, toss another div inside that one that just has the padding dimensions, and use that as your content div. Div soup? Perhaps yes, as you end up with a <div> that is purely for style and not for content... but a div is an empty container, and I say there's nothing wrong with using empty containers to contain things.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset:utf-8">
<title>Test</title>
<style type="text/css">
body { margin: 0; padding: 0; }
#container { border: 1px solid blue;}
#boxA { float: left; width: 50%; padding: 2px; margin-left: -4px; margin-right: -4px; background-color: #fee; border: 1px solid black; }
#boxB { float: left; width: 50%; padding: 2px; margin-left: -4px; margin-right: -4px; background-color: #efe; border: 1px solid black; }
br.clear {clear: both;}
</style>
</head>
<body>
<div id="container">
<div id="boxA">BLah blah blah</div>
<div id="boxB">Blah blah blah</div>
<br class="clear" />
</div>
</body>
</html>
You can remove #container if you want unless there is additional formating to your layout I'm not aware of?
John