如何在子div上显示父div [英] How to display parent div over child div

查看:137
本文介绍了如何在子div上显示父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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆