当我在页面上添加<!DOCTYPE HTML>
时,我发现必须将position: fixed;
添加到CSS中才能将图像显示为“div”的背景,否则我会得到空白的白色背景。为什么这需要这个位置=在这种情况下是固定的?位置:固定有背景图片?
.background_image{
position: fixed; <-----Why is this needed & Why doesn't static work?
background: #000 url(../Images/Image.jpg) center center;
width: 100%;
height: 100%;
min-height:100%;
background-size: cover;
overflow: hidden;
}
这里是示例html。 div中显然还有其他元素,我正在通过标题中的链接导入css。
<body>
<div class="background_image">
</div>
</body>
谢谢...这个伟大的工作。什么被认为是在这里设置背景的正确方法?固定还是静态? – TsTeaTime
@TsTeaTime,在这种情况下保持静态。背景附件固定,用于实现paralx效果。 –