to offset the element that should be position:relative
the coordinates, top
, right
, bottom
and left
are performed for different purposes, depending on whether the element is relative or absolutely positioned.
When is an element offset as opposed to a displaced?
when you actually compensate for using position: relative;
, the element is not removed from the stream, and indeed, the space that the element would occupy if it remained static (by default) is still reserved for it, so you just shift it from it to its original position. Any element following it will appear where it would be done, even if you did not compensate for its predecessor - here is an example
Displacement, not displacement
If you really want to move an element, then you need to remove it from the stream, so there is no free space for it, and then when you use position:absolute;
or fixed .., that is, the difference
Summary
static
by default, and you just use the fields to move around it, it will ignore the coordinates and z-index
relative
- reserved space, the coordinates will move it from it to the original space
absolute
will remove the element from the stream, and the coordinates will be calculated in accordance with it with the block that is closest relative to the positioned ancestor (or the body
element if there is no relatively positioned ancestors)
fixed
does not contain a containing block, i.e. you cannot indicate to which element it should be located in relation to it, it will simply correct itself in relation to the viewport
and finally, the element will not take the z-index
value if it is static by default, therefore position: relative;
without any coordinates applied it is similar to static
, but it is useful for z-indexing and containing a block for absolutely positioned elements
source share