Sometimes, we want to make anchor link go some pixels above where it’s linked to with CSS.
In this article, we’ll look at how to make anchor link go some pixels above where it’s linked to with CSS.
How to make anchor link go some pixels above where it’s linked to with CSS?
To make anchor link go some pixels above where it’s linked to with CSS, we set the scroll-margin-top
style.
For instance, we write
#anchor {
scroll-margin-top: 100px;
}
to set the scroll-margin-top
to 100px to make the browser scroll 100px above the element where the anchor element is when the link for the anchor element is clicked.
Conclusion
To make anchor link go some pixels above where it’s linked to with CSS, we set the scroll-margin-top
style.