前言
近期遇到一個問題——"position:relative"
到底會不會導致元素脫離文檔流?主流觀點是不會,但都給不出一個有說服力的論據。最后我自己佐證了一番,總算有了個結果:
"position:relative"
不會導致元素脫離文檔流。
博文地址:CSS中"position:relative"屬性與文檔流的確切關系
"relative"
與文檔流
說到標準,最權威的自然莫過于CSS標準文檔
。經過一番繁瑣的查找之后(w3c網站找東西是真的累。。。),終于被我找到了。文檔中"positioning-scheme"
一節寫道:

relative-in-flow
鏈接:https://www.w3.org/TR/CSS22/visuren.html#positioning-scheme
An element is called out of flow if it is floated, absolutely positioned, or is the root element. An element is called in-flow if it is not out-of-flow.
當元素是浮動,絕對定位或者根元素時,元素被稱為"流外元素",否則被稱為"流內元素"。
很明顯,"position:relative"
的元素仍在文檔流中。
另外,推薦下一個人認為不錯的文章:
html/css基礎篇——DOM中關于脫離文檔流的幾種情況分析