html - 为什么我的图像不适合 100% 背景

标签 html css

我正在尝试让我的背景图像适合 100% 的屏幕宽度和高度。但它甚至没有显示我的形象。任何可以告诉我我做错了什么的人。

在这里您可以看到我已经尝试过的代码。我不明白为什么它不起作用。

<section id="forside" >
      <div class="container">
            <div class="row">
            </div>
      </div>
</section>

#forside {
    background: url(images/FBIlled.png) no-repeat center center fixed;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
}

我的形象甚至没有得到展示。它只是空白。我希望带有 id="forside"的部分的图像 FBIlled 为 100% 屏幕宽度和高度。完整代码可以在这里显示:https://codepen.io/anon/pen/maLYrZ

最佳答案

更好的主意:

body, html {
  margin: 0;
  height: 100%;
}

.bg { 
  /* The image used */
  background-image: url("img_girl.jpg");

  /* Full height */
  height: 100%; 
  /* Center and scale the image nicely */
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}
<div class="bg"></div>

将代码放在 div 中。
取自https://www.w3schools.com/howto/howto_css_full_page.asp .

关于html - 为什么我的图像不适合 100% 背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54077571/

相关文章:

php - 在 TYPO3 后端中包含 CSS 文件?

jquery - 如何在不更改效果的情况下在可滚动导航中添加下拉菜单?

html - SVG 中的链接图像

html - 证明内容 :center doesn't work

css - 列表框格式(设计/颜色/3d)

css - MVC 最佳实践,响应式设计或动态提供不同的 html

javascript - 提交旧的谷歌表单然后重定向到另一个页面

html - 在另一个 html 中嵌入单个 html 的多个实例,但具有不同的样式

html - 在伪元素前后使用 CSS 创建左箭头

css - 图像未显示正确的尺寸