简体   繁体   English

在下拉菜单上放置一些内容(z索引无效)

[英]Place something on top of a drop down (z-index doesn't work)

How can I place a html element (eg div or img) on top of a select with it's options using javascript, jquery and/or css? 如何使用javascript,jquery和/或css将html元素(例如div或img)及其选择放置在select的顶部? Z-index doesn't work in any browsers. Z-index在任何浏览器中均不起作用。

You will need to use an iframe "shim" with a higher z-index. 您将需要使用具有较高z索引的iframe“填充”。 You can then put you element "on top" of that. 然后,您可以将元素置于“顶部”。

另一种方法是在您隐藏/显示div / img或使用iframe时显示/隐藏下拉菜单。

If you use z-index and you want to layer one item on top of another without showing or hiding them, the best way will be to set absolute positioning on the top layer or possibly both DOM elements. 如果使用z-index并希望将一个项目放在另一个项目的顶部而不显示或隐藏它们,则最好的方法是在顶层或两个DOM元素上都设置绝对位置。

#item1, #item2{
position: absolute;
left:10px;
top:10px;
z-index:1;
}

#item2{
z-index:2;
}

Example HERE 这里的例子

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

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