为什么position:static 会忽略z-index?
请参阅此评论 来自 jquery-ui
// Ignore z-index if position is set to a value where z-index is ignored by the browser
// This makes behavior of this function consistent across browsers
// WebKit always returns auto if the element is positioned
我看到如果元素是 jquery 的 zIndex()
返回 0 位置:静态
。
position:static 不支持 z-index 吗? (它在 Chrome 中适用于我,尚未测试跨浏览器)
See this comment from jquery-ui
// Ignore z-index if position is set to a value where z-index is ignored by the browser
// This makes behavior of this function consistent across browsers
// WebKit always returns auto if the element is positioned
I see that jquery's zIndex()
returns 0 if the element is position: static
.
Isn't z-index supported on position:static? (It works for me in Chrome, haven't tested cross-browser)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因为
position: static
的意思是“忽略来自left
、top
、z-index
等的所有定位指令。 ”。— http://www.w3.org/TR/CSS21/visuren.html#z-index
— http://www.w3.org/TR/CSS21/visuren.html#positioned-element
Because
position: static
means "Ignore all the positioning instructions fromleft
,top
,z-index
, etc.".— http://www.w3.org/TR/CSS21/visuren.html#z-index
— http://www.w3.org/TR/CSS21/visuren.html#positioned-element
对于 flex-items(flex-container 的直接子元素、具有
display: flex
或display: inline-flex
的元素,不会忽略z-index
) 或 grid-items(grid-container 的直接子元素,具有display: grid
或display: inline-grid
的元素)。规格引用
自 W3C Flexbox 规格:
来自 W3C CSS 网格布局规范:
Flexbox 示例
因此,假设我们的布局具有重叠(
.flex-item-two
与.flex-item-one
重叠,例如使用负边距):如果
flex-item-one
索引大于.flex-item-two
的索引,则.flex-item-one
会与重叠>.flex-item-two
。CSS 网格示例
z-index
is not ignored for flex-items (immediate children of flex-container, element withdisplay: flex
ordisplay: inline-flex
) or grid-items (immediate children of grid-container, element withdisplay: grid
ordisplay: inline-grid
).Specs quotation
From W3C Flexbox specs:
From W3C CSS Grid Layout specs:
Flexbox example
So assume we have this layout with overlapping (
.flex-item-two
overlaps.flex-item-one
using e.g. negative margins):If
flex-item-one
index is bigger than.flex-item-two
's,.flex-item-one
then overlaps.flex-item-two
.CSS Grid example