How to prevent anchor links from scrolling behind a sticky header with one line of CSS code example
Example: How to prevent anchor links from scrolling behind a sticky header with one line of CSS
// src/scss/navigation.scss
$sticky-breakpoint: 32em;
// 1. Approximate height of sticky navigation.
[id] {
@media (min-height: $sticky-breakpoint) {
scroll-margin-top: 100px; // 1
}
}
.navigation {
// ...
@media (min-height: $sticky-breakpoint) {
position: sticky;
top: 0;
}
}