[英]CSS HTML align div
我體內有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;
}
當您看到左側,頂部和右側有空格時,結果就是這樣。 我如何刪除該空間?
body{
background:#787777;
font-family:"Droid Sans",Helvetica,Arial,Sans-Serif;
font-size:0.81em;
margin: 0;
padding: 0;
}
您需要刪除<body>
元素周圍的邊距和填充。 瀏覽器默認會添加一個或另一個,因此您需要將它們顯式設置為0:
body {
background:#787777;
font-family:"Droid Sans",Helvetica,Arial,Sans-Serif;
font-size:0.81em;
margin: 0px;
padding: 0px;
}
不同的瀏覽器具有不同的默認樣式,因此將padding 和 margin都設置為0可確保不會出現間隙。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.