::before and ::after position absolute acting like position fixed

后端 未结 2 1715
悲哀的现实
悲哀的现实 2020-12-12 02:57

So I am trying to position my pseudo element with position absolute, but instead, it is acting like its parent is something else.




        
2条回答
  •  悲哀的现实
    2020-12-12 03:27

    Absolute positioned elements need to be contained by a relative parent.

    See example from w3c, play with it by removing the position: relative from parent element. Run it and you'll see how it gets messed up.

    This example comes from the main position article by w3cschools.

    Adding

    p { 
      position: relative;
    }
    

    should fix the issue.

提交回复
热议问题