我经常发现自己将一个类附加到元素上只是为了给它一个位置:相对;这样我就可以使用position:absolute;
如果我写的话会有什么不妥,或者我应该说会有什么问题吗?
* { position: relative; }
或者可能是下面的例子,因为这些通常是我需要相对定位的唯一元素:
div,navbar,footer,section,aside,header,article { position: relative; }
根据W3schools,所有元素都是位置:静态;默认情况下,根据页面的正常流程定位.
“HTML elements are positioned static by default. A static positioned
element is always positioned according to the normal flow of the
page.”
并且根据相同的来源,相对定位的元素也根据页面的正常流程定位,除非被CSS覆盖:
“The content of relatively positioned elements can be moved and overlap
other elements,but the reserved space for the element is still
preserved in the normal flow.”