html - 将背景颜色添加到标记 'html' 会破坏 z-index?

标签 html css z-index less

我在 Less 中定义了以下样式:

html {
  background-color: @playGreen;
}

body {  
  background-color: @background;
  background: url(../images/pattern/cream_dust.png) repeat 0 0;
}

.backStripe {
  background-color: @playGreen;
  position: absolute;
  top: 0;
  width: 100%;
  height: 125px;
  z-index: -9;
}

在我的 Html 代码中(删除了不相关的元素):

<html>
  <head>[...]</head>
  <body>
    <div class="backStripe">&nbsp;</div>
    [... other code ...]
  </body>
</html>

给定的 css 的想法是使用具有 position: absolute 和低 z-index 的 div 将固定大小的彩色条纹设置为背景。

如果我不向 html(标签本身)添加任何样式,它会按预期工作。但是,如果我将 background-color 添加到 html(以避免在短页面底部出现空白),则 backStripe div 将不再显示, 它变得完全隐藏。

知道为什么吗?如何让 div 与 htmlbackground-color 一起工作?

最佳答案

您已为 .backstripe 指定了 z-index。这将它置于 html 元素之下。如果 html 元素不透明,它将隐藏 .backstripe 元素。

坚持使用正 z 索引。

关于html - 将背景颜色添加到标记 'html' 会破坏 z-index?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15013531/

相关文章:

jquery - 使用 jquery 鼠标悬停时如何更改链接颜色

javascript - 使用 z-index 放在前面后下拉列表停止工作

html - 带有绝对 DIV 标签的页面随着内容展开中间变大

html - 强制网页光标

javascript - SyncFusion JS 图表 - 工具提示行为错误

reactjs - Semantic-UI-React Loading 组件后面的这些单选按钮的 z 索引是否不正确?

html - 在内联 block 的 div 上使用 z-index

javascript - 通过 jQuery 或 javascript 重新启动 css 转换

css - body :hover apply to? 在哪里

html - 弄清楚为什么 django 现在找不到我的模板的脚本、样式表和插件