Disable crash in this case
If you check the following demo HTML code, you will see an unexpected orange border appear on all browser pages (I checked) at the top of the page. If the <p> tag is replaced with a <div> tag, everything works as expected.
<!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>Test Lay-Out</title>
<style>
html{
overflow: auto; /*for IE*/
height: 100%;
}
body{
background-color: orange;
margin: 0;
height: 100%;
}
#page{
background-color: green;
height: 100%;
margin-bottom: -50px;
}
#footer{
background-color: red;
height: 50px;
}
</style>
</head>
<body>
<div id="page">
<p>test</p>
</div>
<div id="footer">footer</div>
</body>
</html>
This is due to the <p> having a top margin and collapsing the border to its parent. While this is a desirable effect for creating text paragraphs and the like, it is rarely useful for layouts.
How can I make sure no borders are added to certain elements (in this case, from <to parent div)?
- UPDATE -
Since all the answers seem to go down to "disable padding on paragraph", I reworked my question a bit and changed the title.
Removing the pad from p is a remedy for the symptom, not the cause.
a source to share
This is a bit lame, but I actually found it myself.
Once again, crumbling borders bring me down. Here is a nice forum post that describes it. In my design, it was appropriate to remove the marker from the <p> element. From what I've read, the next best thing is giving parents a tiny margin.
a source to share
Yes, there will be a space at the top because the paragraph leaves some space before and after. The following will remove the space, try:
<!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>Test Lay-Out</title>
<style>
html{
overflow: auto; /*for IE*/
height: 100%;
}
body{
background-color: orange;
margin: 0;
height: 100%;
}
#page{
background-color: green;
height: 100%;
margin-bottom: -50px;
}
#page p.first{
margin-top:0;
}
#footer{
background-color: red;
height: 50px;
}
</style>
</head>
<body>
<div id="page">
<p class="first">test</p>
</div>
<div id="footer">footer</div>
</body>
</html>
a source to share