David wrote:
So you have an element with content width of 100% of the parent elements
content area, then you add margin or padding. 1005 + something greater than
zero is going to equal more than 100%.
Here's an example to illustrate the problem I'm having. I set up two
divs (left-content and right-content), I'd like a 1em margin around
both divs, as well as inbetween them. My goal is to have the content
in these two divs what real estate remains after those margins, and
resize as the browser resizes.
Here's what I did:
· Set html rules to 100% width & height, with 0 margin to establish
inheritance.
· Set body to 100% width & height, but added a 1em margin to surround
the page.
· Created the two content divs "left-content" and
"right-content", set height and width to 100% , added some color,
padding and a little text.
· To establish the 1em "margin" between the two divs, I created
parent divs "left" and "right". Both of these are float:left
so they display side by side, height:100% and width:50%, but I added a
..5em padding in the center to establish the 1em "margin" between
the nested content divs. (code below).
I expected that this would work, but when testing in Foxfire and IE7,
it doesn't. If you reduce #left,#right {width:40%}, you'll see that
the 1em "margin" between the two divs doesn't appear in Foxfire or IE7.
Clearly, my understanding of how this works is off. How would you make
this work?
Thanks!
Mike
Here's my code:
<!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" xml:lang="en" lang="en">
<head>
<style type="text/css" media="screen">
html {
height: 100%;
width: 100%;
margin: 0;
}
body {
height: 100%;
width: 100%;
margin:1em;
}
#left {
padding-right:1em;
}
#right {
padding-left:1em;
}
#left,#right {
float:left;
width:40%;
height:100%;
}
#left-content {
height:100%;
width:100%;
padding:1em;
background-color:red;
}
#right-content {
height:100%;
width:100%;
padding:1em;
background-color:blue;
}
</style>
</head>
<body>
<div id="left">
<div id="left-content">Left Content.</div>
</div>
<div id="right">
<div id="right-content">Right Content.</div>
</div>
</body>
</html>