我希望图片覆盖页面上的所有内容,但是<header>
但是,底部总是有一条白色的空间。
我使用margin-right
和margin-left
来覆盖边,但margin-bottom
没有填充底部的空白区域。
header {
margin-bottom: 20px;
}
h1 {
text-align: center;
}
nav {
text-align: center;
}
ul {
list-style-type: none;
}
li {
display: inline;
padding-right: 5px;
padding-left: 5px;
}
li a {
color: black;
text-decoration: none;
}
#wrapper {
background-image: url(rome.jpg);
-webkit-background-size: 100% 600px;
background-repeat: no-repeat;
height: 600px;
margin-right: -8px;
margin-left: -8px;
}
&#13;
<header>
<h1>Colin Bruin</h1>
<nav>
<ul>
<li><a href="home.html">Home</a>
</li>|
<li><a href="code.html">Code</a>
</li>|
<li><a href="webpages.html">Webpages</a>
</li>|
<li><a href="articles.html">Articles</a>
</li>|
<li><a href="resume.html">Resume</a>
</li>
</ul>
</nav>
</header>
<div id="wrapper">
<main>
</main>
</div>
&#13;
答案 0 :(得分:2)
body
默认情况下有一些margin
,这就是为什么你会看到底部空间以及左/右空间(你使用负边距来 hack fix < / em> it)。
要在margin:0
中解决此设置body
,您不需要左/右1>的否定margin
s
body {
margin: 0
}
header {
margin-bottom: 20px;
}
h1 {
text-align: center;
}
nav {
text-align: center;
}
ul {
list-style-type: none;
}
li {
display: inline;
padding-right: 5px;
padding-left: 5px;
}
li a {
color: black;
text-decoration: none;
}
#wrapper {
background-image: url(//lorempixel.com/1000/1000);
-webkit-background-size: 100% 600px;
background-repeat: no-repeat;
height: 600px;
}
&#13;
<header>
<h1>Colin Bruin</h1>
<nav>
<ul>
<li><a href="home.html">Home</a>
</li>|
<li><a href="code.html">Code</a>
</li>|
<li><a href="webpages.html">Webpages</a>
</li>|
<li><a href="articles.html">Articles</a>
</li>|
<li><a href="resume.html">Resume</a>
</li>
</ul>
</nav>
</header>
<div id="wrapper">
<main>
</main>
</div>
&#13;
答案 1 :(得分:0)
喜欢这个吗?
height:100%;
margin:0;
padding:0;
}
header {
margin-bottom: 20px;
}
h1 {
text-align: center;
}
nav {
text-align: center;
}
ul {
list-style-type: none;
}
li {
display: inline;
padding-right: 5px;
padding-left: 5px;
}
li a {
color: black;
text-decoration: none;
}
#wrapper {
background-image: url(https://placekitten.com/g/1000/1000);
-webkit-background-size: 100% 600px;
background-repeat: no-repeat;
height: 600px;
}
</style> </head>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Colin's Page</title>
<meta charset="utf-8">
<body>
<header>
<h1>Colin Bruin</h1>
<nav>
<ul>
<li><a href="home.html">Home</a>
</li>|
<li><a href="code.html">Code</a>
</li>|
<li><a href="webpages.html">Webpages</a>
</li>|
<li><a href="articles.html">Articles</a>
</li>|
<li><a href="resume.html">Resume</a>
</li>
</ul>
</nav>
</header>
<div id="wrapper">
<main>
</main>
</div>
</body>
</html>