Absolute positioning with percentages giving unexpected results

前端 未结 3 529

Please consider this jsfiddle, containing this html code:

TEST

A

相关标签:
3条回答
  • 2021-02-05 10:09

    add

    position:relative; 
    

    to container div .

    0 讨论(0)
  • 2021-02-05 10:15

    The absolute positioning is applied relative to the next parent element whose position is not static. In your case, that's the full page. Try setting position: relative on the container division.
    See the jsFiddle.

    See: W3C - 10.1 - Definition of "containing block"

    0 讨论(0)
  • 2021-02-05 10:27

    When giving an element absolute position you take it out of the normal flow of the document. Absolute is the very upper left portion of the screen regardless of the other elements in the page. So by saying left: 50% you're saying half way in from the absolute left of the screen.

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