Gentle Shift
position: relative is the most " safe " type of positioning. The element remains in general flow but gains superpowers.
Its Main Functions:
- Micro-shifts: You can move the element with coordinates, while browser " remembers " its original place. Space doesn't collapse, neighbors don't move.
- **Creating a " Base " **: This is the most important role. If you want to place an icon INSIDE a button absolutely, the button MUST be
relative.
.button {
position: relative; /* Now I'm a base for children! */
}
.icon {
position: absolute;
top: -5px; /* Icon will align relative to button */
}
Tip
Use relative for small decorative fixes to not break the overall page structure.