html - 我的图像没有作为完整背景图像放置在 html 页面中

标签 html css web

这是我编写的代码,但它没有工作,我的问题是代码工作但图像没有按预期显示

 .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;

   }

这不顺利

this the result that i had

最佳答案

无法从您的问题中判断出来,但如果您希望页面上的任何元素覆盖整个页面,则必须确保正文边距和填充都设置为零。

如果此元素包含在另一个元素中,则该元素必须允许图像扩展到其边界之外,或者该元素也必须是全尺寸的。

下面是一个在 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">&nbsp;</div>

关于html - 我的图像没有作为完整背景图像放置在 html 页面中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54295238/

相关文章:

javascript - JQuery 中的自动检查单选按钮(根据另一个值将单选按钮标记为选中/未选中)

html - 我无法使用 css 设置表格的上边距

css - 通用选择器 CSS

c# - 将对象转换为特定类型 C#

javascript - 使用 Jsoup Java 从 Wep Pages 获取数据

html - 图片有时无法加载到我的网站上

javascript - 使用appendChild()将文本放入svg内

html - 将 <div> 放在 <p> 内就是添加一个额外的 <p>

javascript - 音乐播放器跳过向前/向后功能 JQuery

jquery - MVC 损坏的图像路径