这是我编写的代码,但它没有工作,我的问题是代码工作但图像没有按预期显示
.about-bg{
background: url(../img/about.jpg) no-repeat top center fixed !important;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
height: 100vh;
width: 100%;
background-position: top center;
}
这不顺利
最佳答案
无法从您的问题中判断出来,但如果您希望页面上的任何元素覆盖整个页面,则必须确保正文边距和填充都设置为零。
如果此元素包含在另一个元素中,则该元素必须允许图像扩展到其边界之外,或者该元素也必须是全尺寸的。
下面是一个在 div
中将纯蓝色图片设置为背景图像的示例:
body {
margin: 0;
padding: 0;
}
.about-bg {
background: url(http://via.placeholder.com/150/0000FF/808080) no-repeat top center;
background-size: cover;
height: 100vh;
width: 100vw;
}
<div class="about-bg"> </div>
关于html - 我的图像没有作为完整背景图像放置在 html 页面中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54295238/