z-index不使div出现在另一个div的顶部 [英] z-index not making div appear on top of another div
问题描述
index和即时通讯出现问题.我有这个按钮,单击时它会显示在内容上,但如果它也尝试将其z索引设置为单击,则它不会与前面的div重叠.到目前为止,这是我的代码
index and im having a problem. i have this button that when click, it will show to content but it does not overlap the div in front if it i have also tried to set its z-index on click here is my code so far
<script type="text/javascript">
function change()
{
alert("Asd");
$('#account-container').css('z-index', 11);
}
这是它的样子
我应该怎么做的任何想法?非常感谢
any idea on what i should do? thanks so much
推荐答案
更高的z-index
是不够的.这两个元素都必须定义为position
,并且必须为absolute
和/或relative
.
Higher z-index
is not enough. Both elements must have position
defined and it should be absolute
and / or relative
.
我会选择将relative
用作父级,将absolute
用作子级(然后也使用top
/left
进行定位).下一步都使用z-index
进行播放,其中子级(或必须在最上面的图层)的值更高.
I would go with relative
for parent and absolute
for child (then also use top
/ left
to position). Next play with z-index
for both, where higher value is for the child (or the layer that must be on top).
在大多数情况下,z-index
应该与position
一起使用但并非总是如此.感谢Michael_B指出这一点.
In most cases z-index
should go together with position
but not always. Thanks to Michael_B for pointing that out.
这篇关于z-index不使div出现在另一个div的顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!