Irakli Lekishvili
Irakli Lekishvili

Reputation: 34198

CSS HTML align div

I have div tag inside body

html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<link href="style.css" rel="stylesheet" type="text/css" />

</head>

<body>

<div id="header">
</div>

</body>
</html>

css:

body{
    background:#787777;
    font-family:"Droid Sans",Helvetica,Arial,Sans-Serif;
    font-size:0.81em;
    }

#header{
    height:100px;
    background:#000000;
    width:100%;
    margin:0px;
    }

and here is result as you see there is spaces left, top and right. How i can remove this spaces? enter image description here

Upvotes: 0

Views: 144

Answers (2)

Bojangles
Bojangles

Reputation: 101543

You need to remove the margin and padding around the <body> element. Browsers will add one or the other by default, so you need to explicitly set them to 0:

body {
    background:#787777;
    font-family:"Droid Sans",Helvetica,Arial,Sans-Serif;
    font-size:0.81em;
    margin: 0px;
    padding: 0px;
}

Different browsers have different default styles, so setting both padding and margin to 0 ensures you don't get a gap.

Upvotes: 2

Zoltan Toth
Zoltan Toth

Reputation: 47687

body{
    background:#787777;
    font-family:"Droid Sans",Helvetica,Arial,Sans-Serif;
    font-size:0.81em;

    margin: 0;
    padding: 0;
}

Upvotes: 3

Related Questions