Position overlay div

前端 未结 3 814
轮回少年
轮回少年 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条回答
  • 2020-12-19 17:36

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

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2020-12-19 17:51
    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.

    0 讨论(0)
提交回复
热议问题