2012-01-29 100 views
0

我體內div標籤CSS HTML對齊DIV

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; 
    } 

,這裏是導致你看到有位左,上,右。我如何刪除這個空間? enter image description here

回答

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

    margin: 0; 
    padding: 0; 
} 
+0

只需添加餘量:0身體選擇器應該這樣做 – Josh 2012-01-29 17:07:53

+0

您可以請回答http://stackoverflow.com/questions/9943560/html-alignment-issue-in-one-machine-only-both-ie8? – Lijo 2012-03-30 13:28:54

2

您需要刪除<body>元件周圍的margin和padding。瀏覽器將添加一種或另一種默認,所以你需要明確它們設置爲0:

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

不同的瀏覽器有不同的默認樣式,所以同時設置填充餘量爲0,確保您不會得到一個溝。