我试图将图像定位在页面顶部,并以 51 像素的高度拉伸(stretch)到页面两侧。但是,图像与页面顶部和页面两侧之间存在间隙。你能告诉我我做错了什么吗?
#background {
width: 100%;
height: 100%;
position: absolute;
left: 0px;
top: 0px;
z-index: 0;
}
.stretch {
width:100%;
height:100%;
}
#twitter {
background: url(http://maxk.me/test/img/twitterbg.png) repeat;
height: 51px;
width: 100%;
position: fixed;
}
HTML
<html>
<head>
<title>title</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
<div id="background">
<img src="...." class="stretch" alt="" />
</div>
<div id="twitter">
</div>
</body>
</html>
最佳答案
您需要删除 body
上的默认 margin
:
html, body {
margin: 0;
padding: 0
}
您还应该在第一行添加一个有效的文档类型:
<!DOCTYPE html>
没有这个,你的页面将是very broken在 Internet Explorer 中,不同浏览器之间通常不一致。
关于html - 页面顶部图像边框之间的间隙html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7134013/