Position Relative vs Absolute?

前端 未结 10 1666
忘了有多久
忘了有多久 2020-11-22 08:16

What is the difference between position: relative and position: absolute in CSS? And when should you use them?

10条回答
  •  佛祖请我去吃肉
    2020-11-22 08:40

    Position Relative:

    If you specify position:relative, then you can use top or bottom, and left or right to move the element relative to where it would normally occur in the document.

    Position Absolute:

    When you specify position:absolute, the element is removed from the document and placed exactly where you tell it to go.

    Here is a good tutorial http://www.barelyfitz.com/screencast/html-training/css/positioning/ with the sample usage of both position with respective to absolute and relative positioning.

提交回复
热议问题