[英]HTML Background color not filling whole page?
嘿,這里的每個人都是問題的圖片:
我希望它填充綠色框左側和頂部的空白區域。
HTML:
<!DOCTYPE HTML>
<html>
<head>
<LINK href="style.css" rel="stylesheet" type="text/css">
<link href='http://fonts.googleapis.com/css?family=Montserrat:700' rel='stylesheet' type='text/css'>
<title>Test page</title>
</head>
<body>
<div id="container" name="header">
<h1>Blegh</h1>
<style>
#container {font-family: 'Montserrat', sans-serif;}
</style>
</div>
</body>
</html>
CSS:
#container{
background-color: #58FA58;
margin-left: auto;
margin-right: auto;
text-align: center;
height: 100px;
width: 100%;
}
這是因為瀏覽器。 默認的瀏覽器有邊距和填充,你應該在所有項目中將填充和邊距設置為零
body{
margin: 0px;
padding: 0px;
}
你將div heigt設置為100 px :)
為了使div像笨蛋一樣,你有這個CSS
* {
margin: 0;
}
html, body {
height: 100%;
}
#container{
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -20px;
}
.footer, .push {
height: 20px;
}
你必須刪除身體邊緣。 將此添加到您的CSS:
body {
margin: 0px;
padding: 0px;
}
將它添加到你的style.css:
html, body {
margin: 0;
padding: 0;
}
應用邊距和填充為0將允許所有元素到達頁面邊框。 但是,如果您希望顏色填充整個頁面(這似乎是實際問題),請將背景顏色應用於body標簽。
body {
margin: 0px;
padding: 0px;
background-color: #58FA58;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.