Position
The position property specifies the type of positioning method used for an element. It is a crucial property for controlling the layout of elements on a web page.
Here's an example of using different position values:
.static {
ㅤposition: static;
}
.relative {
ㅤposition: relative;
ㅤtop: 20px;
ㅤleft: 20px;
}
.absolute {
ㅤposition: absolute;
ㅤtop: 50px;
ㅤright: 0;
}
.fixed {
ㅤposition: fixed;
ㅤbottom: 0;
ㅤleft: 0;
}
.sticky {
ㅤposition: sticky;
ㅤtop: 0;
}
When using position other than static, you can use the top, right, bottom, and left properties to position the element:
.element {
ㅤposition: absolute;
ㅤtop: 50px;
ㅤleft: 100px;
}
Understanding and properly using the position property is essential for creating complex layouts and controlling the placement of elements on your web pages.