小编Pat*_*and的帖子

CSS z-index 不适用于子元素

我尝试过一个个人项目来制作菜单,这些菜单在最高层(z-index 3)上打开,因此它们覆盖了我的板,但它们所在的标题位于最低层(z-index 1),因此板是分配给中间层(z-index 2)。从逻辑上讲,这对我来说看起来不错,但菜单显示为低于 z-index 2...我已经没有办法解决这个问题了。

* {
  margin: 0;
  padding: 0;
}
#header {
  width: 512px;
  height: 256px;
  position: fixed;
  z-index: 1;
  background-color: red;
}
div>ul {
  width: 512px;
  height: 128px;
  position: fixed;
  z-index: 3;
  background-color: blue;
}
ol {
  width: 480px;
  height: 320px;
  margin: 32px 16px 0 16px;
  position: fixed;
  z-index: 2;
  background-color: green;
}
Run Code Online (Sandbox Code Playgroud)
<div id="header">
  <ul></ul>
</div>
<ol>
</ol>
Run Code Online (Sandbox Code Playgroud)

CodePen 示例

html css z-index css-position

-1
推荐指数
1
解决办法
5443
查看次数

标签 统计

css ×1

css-position ×1

html ×1

z-index ×1