如何在子div上显示父div [英] How to display parent div over child div
问题描述
如果我有这个:
<div id='parent'>
<p>Parent stuff here</p>
<div id='child'>Child stuff here</div>
</div>
有没有一种方法可以使父div在不使用position:absolute
的情况下出现在子div的上方?基本上,您根本不会看到子div. z-index
似乎不起作用.我想使用透明的PNG进行此操作,以便在鼠标悬停时突出显示某些div-透明性将使底层内容仍然可见.
谢谢!
z-index
仅在该元素上设置了static
以外的位置(默认值)时才有效.将position: relative;
添加到相关元素中,然后z-index
将起作用.这是一个示例: http://jsfiddle.net/sl1dr/8gR6V/
If I have this:
<div id='parent'>
<p>Parent stuff here</p>
<div id='child'>Child stuff here</div>
</div>
Is there a way to make the parent div appear overtop of the child div without using position:absolute
? Basically, you wouldn't see the child div at all. z-index
doesn't seem to work. I want to do this with a transparent PNG so that I can highlight certain divs on mouseover - the transparentness will allow the under stuff to still be seen a little.
Thanks!
z-index
will only work if a position other than static
(the default) is set on that element. Add position: relative;
to the relevant element and z-index
will work. Here is an example: http://jsfiddle.net/sl1dr/8gR6V/
这篇关于如何在子div上显示父div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!