作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这可能是一个关于 z-index
的更高级的 CSS 问题:
你可以在http://jsfiddle.net/cPdge/6/中看到它
使用当前的 Firefox、Chrome、Safari 或 IE 9,您应该会在父 DIV 的顶部看到蓝色的 DIV。
我们如何让蓝色方框位于父 DIV 之下? 注意:如果父 DIV 的 z-index 被移除,那么蓝色的 DIV 将在它下面,但是如果 z-index 没有被移除并保持为 0
会怎么样? ? 为什么是 z-index
的 0
或者没有 z-index
指定有区别吗?通常,未指定与 0
相同.
该页面中的代码是:
<div id="box1">
some content
<div id="subbox1">blue
</div>
<div id="subbox2">orange
</div>
</div>
和 CSS:
#box1 { width: 600px; height: 400px; border: 6px dashed orange;
position: absolute; top: 100px; left: 100px; background: #ffe; z-index: 0 }
#subbox1 { width: 300px; height: 200px; border: 6px dashed orange;
position: absolute; top: 310px; left: 100px; background: #eff; z-index: -10000 }
#subbox2 { width: 300px; height: 200px; border: 6px dashed orange;
position: absolute; top: 210px; left: 200px; background: #fc9; z-index: 2000 }
最佳答案
如果 box1
没有定位,你的否定 z-index
会起作用,否则子框在 child stacking context 中, 并且不能定位在父框之下。
Why is a z-index of 0 or no z-index specified make a difference?
这个问题的答案在我链接到的文档中:要创建一个新的堆叠上下文,元素必须被定位并且有一个声明的z-index
(或者有opacity
小于 1,这有点奇怪...)。
关于css - 棘手的 : In CSS and HTML, 如果容器的 z-index 为 0,如何使子 DIV 位于容器下方?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10667226/
我是一名优秀的程序员,十分优秀!