简体   繁体   English

Z索引溢出

[英]overflow with z-index

I have the following HTML markup 我有以下HTML标记

<div id="main">
 <div id="div1" style="position:relative;"></div>
 <div id="div2" style="z-index:-1; position:relative; overflow:auto; height:500px;"></div> 
</div>

In div2 I load data dynamically and the content could exceed the divs height, so I used a overflow:auto property to show a scrollbar. div2我动态加载数据,内容可能超过divs高度,因此我使用了overflow:auto属性来显示滚动条。 The problem is that the scrollbar appears in all browsers, but it is working just in IE8/9, FireFox and Chrome. 问题是滚动条出现在所有浏览器中,但仅在IE8 / 9,FireFox和Chrome中有效。 In other browsers you see the scrollbar, but without functionality. 在其他浏览器中,您会看到滚动条,但没有功能。

Your div2 has z-index of -1. 您的div2的z-index为-1。 So it is behind. 所以它落后了。 That's why it does not work. 这就是为什么它不起作用。

I had a similar issue and found that the negative z-index was indeed the problem and that a positive z-index was the solution. 我有一个类似的问题,发现负z索引确实是问题,而正z索引是解决方案。 Try setting the z-index of div2 to 0 or some positive value X and then set the z-index of your other elements to a z-index that's greater than 0 or X. A negative z-index causes an item to be "below" the level of mouse interaction, thus the new z-indicies will cause div2 to be behind other content with a higher z-index while still allowing for mouse interaction. 尝试将div2的z-index设置为0或某个正值X,然后将其他元素的z-index设置为大于0或X的z-index。负的z-index导致项目位于“以下鼠标互动的程度,因此新的z指标将使div2落后于其他具有更高z索引的内容,同时仍允许鼠标互动。

See this question for more detail: Weird z-index behaviour preventing mouse interactions: bug or normal? 有关更多详细信息,请参见此问题: 奇怪的z索引行为阻止了鼠标交互:错误还是正常?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM