tags:

views:

72

answers:

4

In Firefox 3.5.8 on Windows, I get a vertical scrollbar when I use this HTML:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Haloooo1 - T3</title>
<style type="text/css">
  html, body, div {height: 100%; margin: 0; padding: 0; }
  #main {
    width: 320px;
    background:#7C7497;
    height : 100%;
    margin: 0 auto;
  }
</style>
</head>
<body>
<div id='main'>
<p>Hello</p>
</div>
</body>
</html>

alt text

Q1. Can anyone explain why?
Can anyone explain how to remove it?

Q2. Can anyone explain why there is a cushion of whitespace above the div? Can anyone explain how to remove it?

+5  A: 

Add this:

p {margin: 0; }

Your p element has some margin on the top.

Let me recommend using a CSS reset file. I like the YUI one.

Dustin Laine
As padding is inside the box IIRC it is not needed.
Maciej Piechotka
Using reset.css like the one from Yahoo! is a must in modern html/css/javascript development. You should try it! You'll get less differences between browsers than without it.
shfx
+2  A: 

According to firebug it is margin in <p>. At least in 3.6 setting margin-top to p solves problem.

p {
    margin-top: 0;
}
Maciej Piechotka
+1 for mentioning to use firebug.
Blair McMillan
+1  A: 

It's the paragraph.

If you add

 p { margin: 0px; padding: 0px } 

all gets well, including the scroll bar.

Why the paragraph feels entitled to leave its parent element like that, I'm not entirely sure yet.

Pekka
100% height probably confuses FF. The margin should render inside the div.
Ishmael
A: 

A1. You are getting a scroll bar because the div has a size of 100% of i browser window not 100%. Because the div is the same size as the browser window but is shifted down a scroll bar is needed to display the bottom of the div.

A2. The whitespace above the div is the top margin of the p element.

Robert Menteer