Google Chrome 不尊重 z-index
从标题来看,似乎只有 Chrome 不配合。请注意,无法单击屏幕左侧的表单字段。这只发生在某些页面(例如联系页面)。看起来 #left_outer div 覆盖了内容。当我通过 Firebug 或 Chrome 的开发工具编辑 css 时,它可以工作,当我编辑实际的 css 并刷新时,它不起作用。
有什么想法吗?
链接:
谢谢!
As per the title, it seems only Chrome isn't playign along. Note that form fields cannot be clicked on which are on the left portion of the screen. This only occurs on some pages (such as the Contact page). It appears that the #left_outer div is overlaying the content. When I edit the css via Firebug or Chrome's dev toools, it works, when I edit the actual css and refresh, it does not.
Any ideas?
LINK:
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
通常,当您设置了
z-index
属性,但事情没有按您预期的方式工作时,它与position
属性有关。为了使
z-index
正常工作,需要“定位”元素。这意味着它的position
属性必须设置为absolute
、relative
或fixed
之一。请注意,如果您使用
position:absolute
和top
、left
、,您的元素也将相对于定位的第一个祖先进行定位>右
、下
等。Usually when you have set the
z-index
property, but things aren't working as you might expect, it is related to theposition
attribute.In order for
z-index
to work properly, the element needs to be "positioned". This means that it must have theposition
attribute set to one ofabsolute
,relative
, orfixed
.Note that your element will also be positioned relative to the first ancestor that is positioned if you use
position: absolute
andtop
,left
,right
,bottom
, etc.如果没有可供查看的链接,就很难看出问题所在。
您是否在任何地方都有
z-index: -1;
(负数是这里的关键,与数字无关)?我过去发现这会使容器无法进行交互。
祝你好运!
Without a link to look at, it's a bit tough to see what the problem might be.
Do you have a
z-index: -1;
anywhere (a negative number is the key here, doesn't matter the number)?I have found in the past this renders the container void from being interacted with.
Good luck!
Markt 的答案(参见第一个答案)很棒,这是 z-index 属性的“定义”。
Chrome 的具体问题通常与顶部容器底部的溢出属性有关。
因此,对于以下内容:
和样式:
实际发生以下情况(仅限 Chrome,firefox 按预期工作)
“fixed-div”位于“first-container”后面,即使“fixed-div”及其容器(“second-container”)的 z-index 值都大于“first-”容器'。
原因是 Chrome 总是在强制溢出的容器内强制执行边界,即使其后继者之一可能具有固定位置。
我想你可以找到一个扭曲的逻辑......我不能 - 因为使用固定位置的唯一原因是启用“一切之上”行为。
所以错误是...
Markt's answer (see first answer) is great and this is the "by definition" of the z-index property.
Chrome's specific issue are usually related to the overflow property from the top container bottom.
So, for the following:
And styles:
the following actually happens (Chrome only, firefox works as expected)
The 'fixed-div' is behind the 'first-container', even though both 'fixed-div' and its container's ('second-container') z-index value is greater than 'first-container'.
The reason for this is Chrome always enforce boundaries within a container that enforces overflow even though one of its successors might have a fixed position.
I guess you can find a twisted logic for that... I can't - since the only reason for using fixed position is to enable 'on-top-of-everything' behavior.
So bug it is...
我在 Chrome 上遇到了 zIndex 的奇怪问题,我一直在摆弄位置属性以查看是否有任何效果。但是,事实并非如此。事实证明,就我而言,问题出在转换属性上。因此,如果您有变换属性,请将其禁用,应该没问题。其他浏览器可以很好地处理类似的事情,但 Chrome 似乎以不同的方式处理它。
希望这对您有帮助。
I had a weird issue with zIndex on Chrome and I kept fiddling with the position attribute to see if anything worked. But, it didn't. Turns out, in my case, the issue was with the transform attribute. So, if you have a transform attribute in place, disable it and it should be fine. Other browsers work fine with stuff like that, but Chrome seems to play it differently.
Hope this helped you.
Google Chrome 至 84.0.4147.135(官方版本)(64 位)2020 年 2 月 22 日。
自从我上次更新以来,CSS 元素 z-index 在 Chrome 中被破坏了。
Chrome 添加了“z-index: 1;”到 BODY 元素。
它现在错误地显示所有 z-index: ?; BODY 子元素中的值。
设置BODY的位置、z-index并不能解决问题。
更改已经正确的子元素的 z-index 值没有帮助。
我希望这个问题能够得到解决,自从我更新 Chrome 后它就被破坏了。
www.eatme.pro/music 上的 Chrome 84.0.4147.135 错误 - 屏幕小于 500 像素 - 推送播放- z-index 5 的底部栏 #lblBottomBarLink 显示在 z-index 2 的菜单下
(参见图片)
Chrome 84.0.4147.135 中的图像 eatme.pro/music,z-index 5 位于 z-index 2
Google Chrome to 84.0.4147.135 (Official Build) (64-bit) 2020-02-22.
Since my last update, CSS element z-index is broken in Chrome.
Chrome added "z-index: 1;" to the BODY element.
It now wrongly displays all z-index: ?; values in the BODY child elements.
Setting the position, z-index of BODY does not solve the problem.
Changing z-index values of child elements that were already correct does not help.
I hope this issue will be fixed, it is only broken since I updated Chrome.
Chrome 84.0.4147.135 bug on www.eatme.pro/music - screen smaller than 500 px - push play - appearing bottom bar #lblBottomBarLink with z-index 5 is displayed under menu with z-index 2
(see image)
image eatme.pro/music in Chrome 84.0.4147.135 with z-index 5 under z-index 2
我知道这个问题现已解决,但发布的解决方案对我不起作用。这是解决我的问题的方法:
I know this is now resolved but posted solution didn't work for me. Here is what resolved my problem: