div在另一个div [英] div under another div

查看:131
本文介绍了div在另一个div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与css,我可以把一个div在另一个div,而不使用绝对定位?



我有这两个div,我希望白色的一个直接出现在黄色不透明的下面(但不是直接在角落,在角落



如何实现这一点。我已经尝试了 z-index 和相对定位,但是没有效果。



谢谢
http://jsfiddle.net/loren_hibbard/WtGsv/



 

没有使用定位,我添加了一个风格到你的内容div使用负边距: .content {
margin-top:-100px;
}

这里的演示: http://jsfiddle.net/WtGsv/3/



我建议您为 .fixed_width div,其中包含 .content div,并使用id给出负边距父div具有负边距,而不是子div。



但是如果你想使用绝对定位,我在这里更新了你的jsfiddle:
http://jsfiddle.net/WtGsv/12/



基本上,你要在你要使用的其他两个div之间添加一个父div, position:relative; position:absolute; code>


with css, can I put a div under another div without using absolute positioning?

I have these two divs, and I would like the solid white one to appear directly under the one with the yellow opacity (but not direct in the corner, at the corner of the outline).

How can this be accomplished. I've been experimenting with z-index and relative positioning, but to no avail.

Thanks http://jsfiddle.net/loren_hibbard/WtGsv/

解决方案

Without using positioning, I added a style to your content div using negative margins:

.content {
    margin-top:-100px;
}

Working demo here: http://jsfiddle.net/WtGsv/3/

I suggest adding an id to your .fixed_width div which houses the .content div though, and using the id to give the negative margin to, that way the parent div has the negative margin, not the child div.

However if you want to use absolute positioning, I have updated your jsfiddle here: http://jsfiddle.net/WtGsv/12/

Basically, you add a parent div with position:relative; around your other two divs that you want to use position:absolute;

这篇关于div在另一个div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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