Position overlay div

前端 未结 3 817
轮回少年
轮回少年 2020-12-19 17:19

I have a link in a table cell and when the link is clicked I show a hidden div.

Currently I use position: absolute and z-index:10. It works fine, but I would like t

3条回答
  •  Happy的楠姐
    2020-12-19 17:47

    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

提交回复
热议问题