views:

376

answers:

5

Hi!

even after many lines i've written in css and html, the css-behaviour still manages to surprise me - in a bad way.

I was putting together a sample site for a friend to show him how he could build his layout, but Firefox 3.0.5 and IE8 create margins between my #header, #content, and #footer-divs out of nowhere. If i switch in IE7 Mode, the margins disappear.

CSS:

html, body {
   background-color: #fff;
   margin: 0;
   padding: 0;
   width: 100%;
}

#page {
   background-image: url('bg_gradiant.png');
   background-repeat: repeat-y;
   width: 950px; /* 770px + 2 * 90px; */
   margin: 0 auto;
   padding-left: 90px;
}

#header {
   width: 770px;
   margin: 0;
   padding: 0;
}

#header #row1 {
   background-color: #9ab3ba;
   height: 50px;
}
#header #row2 {
   background-color: #517279;
   height: 50px;
}

#content {
   width: 770px;
   background-color: #d7e9ed;
}

#footer {
   background-color: #5eb6cc;
   width: 770px;
   height: 150px;
}

HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xml:lang="de" xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta http-equiv="Content-Style-Type" content="text/css" />
    <link rel="stylesheet" type="text/css" href="./style.css" />
    <title>Test</title>
</head>
<body>
<div id="page">
   <div id="header">
      <div id="row1"></div>
      <div id="row2"></div>
   </div>
   <div id="content">
      <p style="height: 600px">Beware of the Content</p>
   </div>
   <div id="footer">
   </div>
</div>
</body>
</html>

You can view this page here: http://projekte.lx-s.de/web/3dworxxCssHelp/

Browsing through the IE Developer Tools and Firebug showed me that they were no default-margin values set for these div's, but as one can see, they are there. Hope you can give me a hint how to get rid of them - it's seriously driving me crazy.

Thanks in advance!

A: 

You need to use a reset css. You should do this on every Web page/site you develop. A good reset CSS will remove many of the default settings and make cross-browser look and feel much less painless.

There are several of these around such as Eric Meyer's or the Yahoo UI Reset CSS.

cletus
thanks for the tip!
lx
+2  A: 

It's not the DIV but the P tag that has the margin set by default. I tested setting it to 0 and the space disappeared.

Ryan Brunner
so p was the culprit.. - strange that the p-margin reaches out of it's parent div ....
lx
No, it isn't ;) http://www.w3.org/TR/CSS21/box.html#collapsing-margins
David Dorward
+3  A: 

The margins are on the p tag in the #content div

Hope this helps you a little

Anthony
A: 

Add the following to your stylesheet:

* {
    margin: 0;
}
Supertux
A: 

Ryan Brunner has goven the best answer on this subject ever. I've searching for over an hour and no one else has said anything that worked but him.

By the way if the gap check for P tags with no margin at the bottom of a div too!