html - 高度似乎无法在 Chrome 77 上正常工作

标签 html css

我有一个页面可以在 Firefox 上正常运行,但不能在 Chrome 77 上运行。

#container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  height: 100px;
  display: block;
  background-image: linear-gradient(lightblue, rgb(61, 133, 214));
}

#main-section {
  flex-grow: 1;
  background: url("https://picsum.photos/id/15/1000/1000");/* any image you want */
  background-repeat: no-repeat;
  background-size: cover;
}

#main-section-background {
  min-height: 100%;
  height: auto !important;
  background-color: #ffffff;
  opacity: 0.9;
}

.main-content {
  min-height: 100%;
  height: auto !important;
  display: flex;
  justify-content: space-evenly;
}

footer {
  height: 100px;
  background-image: linear-gradient(lightblue, rgb(61, 133, 214));
}
<div id="container">
  <header>
  </header>

  <section id="main-section">
    <div id="main-section-background">
      <div class="main-content">
      </div>
    </div>
  </section>

  <footer>
  </footer>
</div>

背景图像不透明度适用于 Firefox。对于 chrome,height 和 min-height 属性没有任何效果,不透明度也不可见。 我尝试了几种方法来强制调整内容的高度,但看起来 Chrome 只在实际的 HTML 内容上应用了不透明度(为清楚起见未放在这里)。

最佳答案

您可以优化您的代码,只保留应用多重背景的main-section:

#container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  height: 100px;
  display: block;
  background-image: linear-gradient(lightblue, rgb(61, 133, 214));
}

#main-section {
  flex-grow: 1;
  background: 
    linear-gradient(rgba(255,255,255,0.9),rgba(255,255,255,0.9)),
    url("https://picsum.photos/id/15/1000/1000");/* any image you want */
  background-repeat: no-repeat;
  background-size: cover;
  display: flex;
  justify-content: space-evenly;
}

footer {
  height: 100px;
  background-image: linear-gradient(lightblue, rgb(61, 133, 214));
}

body {
 margin:0;
}
<div id="container">
  <header>
  </header>

  <section id="main-section">
    
  </section>

  <footer>
  </footer>
</div>

关于html - 高度似乎无法在 Chrome 77 上正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58144268/

相关文章:

javascript - 将两个不同的html页面内容复制到一个页面中

css - 两个按钮并排

css - 列表项的 Sprite

Chrome 和 Firefox 的 CSS 动画

html - 如何更改选择列表中的默认蓝色

css - 对具有相同 tabindex 的所有元素应用相同的效果,使其成为其中之一的焦点

javascript - 侧边栏将幻灯片切换到右侧

范围输入的 JavaScript 位置问题

html - 仅在 Safari 中背景视频位置不正确

javascript - 带有关闭按钮的警告消息弹出窗口