CSS Layout - The position Property
CSS Layout - The position Property
The position property specifies the type of positioning method used for an
element (static, relative, fixed, absolute or sticky).
The position property specifies the type of positioning method used for an
element.
static
relative
fixed
absolute
sticky
Elements are then positioned using the top, bottom, left, and right properties.
However, these properties will not work unless the position property is set
first. They also work differently depending on the position value.
position: static;
Static positioned elements are not affected by the top, bottom, left, and right
properties.
An element with position: static; is not positioned in any special way; it is
always positioned according to the normal flow of the page:
Example
div.static {
position: static;
position: relative;
Example
div.relative {
position: relative;
left: 30px;
ADVERTISEMENT
position: fixed;
A fixed element does not leave a gap in the page where it would normally
have been located.
Notice the fixed element in the lower-right corner of the page. Here is the CSS
that is used:
Example
div.fixed {
position: fixed;
bottom: 0;
right: 0;
width: 300px;
position: absolute;
Note: Absolute positioned elements are removed from the normal flow, and
can overlap elements.
This <div> element has position: relative;This <div> element has position:
absolute;