Difference between static and relative positioning

后端 未结 8 1317
野性不改
野性不改 2020-11-27 11:09

In CSS, what is the difference between static (default) positioning and relative positioning?

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-27 11:36

    In answer to "why CSS would still implement position: static;" in one scenerio, using position:relative for a parent and position:absolute for the child limits the scaling width of the child. In a horizontal menu system, where you could have 'columns' of links, using 'width:auto' does not work with relative parents. In this case, changing it to 'static' will allow the width to be variable dependent on the content within.

    I spent a good few hours wondering why I couldn't get my container to adjust based on the amount of content within it. Hope this helps!

提交回复
热议问题