开发者

How can I absolutely position an element via jQuery?

I have a div nested in a td and the div class is set to absolute:

.mouseover-tooltip {
    width:400px;
    -webkit-border-radius: 10px;
    -moz-border-radius: 10px;
    border-radius: 10px;
    border:1px solid #555;
    background-color:#FFFFFF;
    -webkit-box-shadow: #B3B3B3 9px 9px 9px;
    -moz-box-shadow: #B3B3B3 9px 9px 9px;
    box-shadow: #B3B3B3 9px 9px 9px;
    position:absolute;
    z-index:10;
    left:-9999px;
    padding:5px;
    displa开发者_如何学Cy: none;
}

But when I give it a top of 0, it aligns itself with the top of it's parent. That's not what I want. I want to work in an absolute world.


But when I give it a top of 0, it aligns itself with the top of it's parent.

That's how absolute positioning works: relative to the offset parent.1 From your statement I can infer that the element's parent is positioned.2

Use .offset() to set the position of the element relative to the document, or change the HTML structure such that the element's offset parent is the <body>.


1. The closest positioned ancestor or the containing block.
2. That is, the parent has computed position of relative, absolute, or fixed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜