i’ve got a client where clicking nav anchor links scrolls to the right section but the header sits right on top of the heading. classic problem, but the fix i usually use (adding scroll-margin-top to the target element) isn’t working consistently across browsers for them.
works fine in chrome, patchy in safari. wondering if anyone’s landed on a cleaner solution or if there’s something specific about how dawn handles the sticky header height variable that i’m missing.
Ah, this depends on where you apply this property – scroll-margin-top works for target elements (as in your code), while scroll-padding-top – on container – try this on body, like
body {
scroll-padding-top: var(--header-height);
}
yeah that’s a fair point on scroll-padding-top vs scroll-margin-top. i’d been applying it to the target elements but putting it on the html or scroll container is probably cleaner for a whole-site fix.
html {
scroll-padding-top: 8rem;
}
going to try that first before reaching for JS. cheers.