confusednerd
confusednerd

Reputation: 164

White border at the top

Why would this code leave a white strip at the top of the page in google chrome ?

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>title goes here</title>
</head>

<body style="margin:0px 0px 0px 0px;padding:0px 0px 0px 0px">
<form id="form1" runat="server" style="padding:0px 0px 0px 0px;margin:0px 0px 0px 0px">
        <div style="background-color: blue;">
            <p>&nbsp</p>
        </div>
    </form>
    <p>&nbsp;</p>
</body>
</html>

Upvotes: 6

Views: 1929

Answers (4)

Shen
Shen

Reputation: 174

The white line is coming from the white space left behind by the line break created by the p tag. Just remove the p tag and it will be gone.

    <div style="background-color: blue;">
           &nbsp
    </div>

Upvotes: 0

user1320635
user1320635

Reputation:

The p-tag has a margin that affects its parents.

Add overflow: auto; to the div with the background. That prevents margins from collapsing

Upvotes: 10

suff trek
suff trek

Reputation: 39777

Give margin:0; padding:0; to the <p> inside of DIV.

Upvotes: 1

MrMerrick
MrMerrick

Reputation: 262

Try adding margin:0; and padding=0; to the htmlelement as well.

Also, this is a bit far-fetched, but I experienced a similar problem with php files where a utf-8 encoded one with BOM would create an empty line before everything else.

Upvotes: 0

Related Questions