Make sticky positioning work with internal links and scroll padding #48656
Labels
[Feature] Link Editing
Link components (LinkControl, URLInput) and integrations (RichText link formatting)
[Type] Enhancement
A suggestion for improvement.
What problem does this address?
I would like sticky positioning introduced in 6.2 to work fully with smooth scrolling (scroll-behavior: smooth) and scroll-padding-top.
Currently, an internal link scrolls to the wrong place when sticky positioning is set on a group.
A simple example in 6.2 beta 4 in the Twenty Twenty-Three theme. The headings should not be covered up when you scroll to them.
Instead, the actual link location on the page should be visible when you scroll to it, and not covered up by the fixed group. Something like:
What is your proposed solution?
Scrolling with sticky elements is a great modern Web feature that requires only a bit of CSS and Javascript to fully implement.
Many web sites, like Canva web pages out of the box, implement stick headers with scroll-padding to avoid the problem of internal links scrolling to the wrong place.
However, to do this correctly, the size of the sticky element needs to be calculated, typically in a short Javascript snippet like this used to create second example above:
stickyBlockHeight = stickyBlockElement.offsetHeight;
document.documentElement.style.setProperty('--scroll-padding', stickyBlockHeight + "px");
A simple solution would be to generate a new CSS variable that would contain the height of the sticky element(s).
Then add in the CSS variable, changing:
to something more like:
But this likely misses many use cases for scroll padding like:
A modern-Web-first design review would help.
The text was updated successfully, but these errors were encountered: