jquery css overlay div over another div?

I tried to find to overlay a div over another then i found out this

But this doesnt seems to works for me ?

I just want it something like :

<div>The div below</div>
<div>OverLay div</div>

Can u please give me a working demo ?


Here is a fiddle for you: http://jsfiddle.net/maniator/J9bjm/

The only thing you need to grasp from it is the position: absolute; and the top: 0; (or however far away from the top of the page that you want it)


Here's another solution that might work in your particular case, using negative margin instad of position:

<div id="one">One</div>
<div id="two">Two</div>

#one, #two, #three, #four {
    background: #ddd;
    height: 100px;
    width: 100px;
}
#two {
    background: #aaa;
    margin-left: 10px; /* Set to 0 for complete overlap */
    margin-top: -80px; /* Set to -100 for complete overlap */
}

http://jsfiddle.net/xatpf/


The first answer seems good to me, but here is a link to the w3schools css position page. The "try it yourself" is a convenient sandbox.

Edit: as noted in the comment, w3schools is not a good reference. I marked the link with strikethrough, but left it live.

链接地址: http://www.djcxy.com/p/75856.html

上一篇: 将一个div覆盖在另一个div上,但不知道div的大小

下一篇: jQuery的CSS覆盖另一个div div?