问题
Does just declaring position:relative
on a div without specify position coordinates such as top,left etc takes it out of normal document ? Plz provide reasoning.
thanks dkj.
回答1:
No it doesn't. relative
positioning doesn't affect the layout, the positioned element is still in its initial place logically, hence the occupied space is reserved.
But it could be displaced visually by top
, right
, bottom
, left
offsets/properties.
9.3.1 Choosing a positioning scheme: 'position' property
relative
The box's position is calculated according to the normal flow (this is called the position in normal flow). Then the box is offset relative to its normal position. When a box B is relatively positioned, the position of the following box is calculated as though B were not offset. [...]
回答2:
No:
Elements that are positioned relatively are still considered to be in the normal flow of elements in the document.
via https://developer.mozilla.org/en-US/docs/Web/CSS/position#Absolute_positioning
来源:https://stackoverflow.com/questions/26560303/does-setting-position-to-relative-on-a-div-takes-it-out-of-document-flow