Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is there a space between the <body> and the <html> element

Tags:

html

css

Why is there a space between the top of the green box and the browser window (in Chrome and Firefox)?

There is an apparent space between the html and body element that I cannot seem to eliminate with the CSS below (and dozens of variations upon it.) there also seems to be some bonus padding on the overall document height, as if some aspect of padding or margin is not being reset to 0.

Helpful tip: http://reference.sitepoint.com/css/collapsingmargins

I solved this problem by using the following code:

div#aiport > *:first-child { margin-top: 0px }

while adding

overflow: hidden;

to the div#airport definition by itself solved the problem correctly. :-)

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>bug</title>
        <link rel="icon" type="image/png" href="bookmarkIcon.png" />
        <style type="text/css">
            html {
                height: 100%;
                min-height: 100%;
                padding: 0px;
                margin: 0px;
            }
            body {
                margin: 0px;
                padding: 0px;
                margin-top: 0px;
                padding-top: 0px;
                width: 100%;
                height: 100%;
                font-size: 16px;
                background: #fff;
            }
            div#airport {
                position: relative;
                z-index: 1;
                top: 0px;
                padding: 0px;
                padding-top: 0px;
                margin: 0px;
                margin-top: 0px;
                margin-left: auto;
                margin-right: auto;
                width: 900px;
                min-width: 900px;
                max-width: 900px;
                background-color: #0f0;
            }
        </style>
    </head>
    <body lang="en">
        <div id="airport">
            <p>Platform</p>
        </div>
    </body>
</html>
like image 700
z t Avatar asked Oct 29 '12 20:10

z t


People also ask

What is the space between an element's border and content?

The Architecture: The content is surrounded by the border, the space between the content and the border is called the padding, while the space between the border and the other elements in the document is called the margin.

Why is there gap between divs?

It's just a margin collapse issue. A 1px padding on #headerbotm (or top border) will suffice.

Which element is given space in HTML?

To add extra space below a line or paragraph of text, or push text down lower on the page once, you can use the <br> tag.


1 Answers

Because your <p>Platform</p> element has a margin that pokes out of its parent <div id="airport"> element and offsets it from the <body>.

like image 99
lanzz Avatar answered Sep 28 '22 00:09

lanzz