我想制作一个页面,通过向下滚动,内容 div 覆盖背景图像。所以我为主体放置了一个背景图像并创建了 2 个 div,它在大窗口大小下工作,但是当我改变窗口大小,并使其变小(以测试响应),图像和内容 div 之间有一个白色间隙。
你能帮我删除它吗?
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>first</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<link href="css/first.css" rel="stylesheet">
<style>
body{
background: url("https://kalamarie123.files.wordpress.com/2012/03/img_7815-2.jpg") no-repeat top center fixed;
background-size:100%;
}
</style>
</head>
<body>
<div class="cover"></div>
<div class="content">Lorem Ipsum is simply dummy text of </div>
</body>
</html>
.cover{
height: 1232px;
width: 100%;
margin: 0;
padding: 0;
color: white;
text-align: center;
}
.content{
width: 100%;
height: 100%;
background: gray;
margin: 0;
padding: 0;
}
最佳答案
你需要让 body 和 html 到页面底部:
body, html {
min-height: 100%;
}
然后将背景设置为background-size: cover;
: https://css-tricks.com/perfect-full-page-background-image/
关于html - 如何使用 css 制作一个页面,背景图像被覆盖,滚动且响应迅速?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35031835/