开发者

Position overlay div

开发者 https://www.devze.com 2023-03-08 12:49 出处:网络
I have a link in a table cell and when the link is clicke开发者_StackOverflow社区d I show a hidden div.

I have a link in a table cell and when the link is clicke开发者_StackOverflow社区d I show a hidden div.

Currently I use position: absolute and z-index:10. It works fine, but I would like to move it a bit to the top and left. When I add top: -10px and left: -10px, the div moves to the position of the window.

How do I make it 10px off the table cell?


You need to set the parent element using position relative then use position absolute on the element you want to position. So if you want it to be positioned based on the table you need to add position: relative to the table (which won't do anything because it is already positioned relative) and position: absolute to the overlay. Absolute positioning takes the element out of the document flow and relative positioning leaves it in the document flow which is why stuff is being moved around. The reason for this is based off how CSS works: http://www.w3schools.com/css/pr_class_position.asp

relative The element is positioned relative to its normal position, so "left:20" adds 20 pixels to the element's LEFT position

absolute The element is positioned relative to its first positioned (not static) ancestor element

You might also be interested in fixed.

fixed The element is positioned relative to the browser window

Here is an Example: http://pastehtml.com/view/av391nzsv.html


position: relative;

instead of

position: absolute;

Relative says to measure top and left from the parent element, absolute says to measure from the top left corner of the page.


use margin-top:-10px; margin-left:-10px;

0

精彩评论

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