diff --git a/theme/stylesheets/base.css b/theme/stylesheets/base.css index 15b455694f..661598be72 100644 --- a/theme/stylesheets/base.css +++ b/theme/stylesheets/base.css @@ -1,6 +1,6 @@ html { font-size: 100%; } -/* scroll-margin-top on headings (content.css) handles the sticky-header +/* scroll-margin-top on content elements (content.css) handles the sticky-header offset for anchor jumps. A page-wide scroll-padding-top here would also apply to focus()-triggered scrolling of anything inside the sticky header itself (e.g. the search trigger), which sits within that reserved band and diff --git a/theme/stylesheets/content.css b/theme/stylesheets/content.css index 75b6ff39ac..73e0e73c3f 100644 --- a/theme/stylesheets/content.css +++ b/theme/stylesheets/content.css @@ -5,11 +5,16 @@ end up wider than every other page. Restore it so widths stay consistent. */ .md-sidebar--secondary[hidden] ~ .md-content > .md-content__inner { margin-right: 1.2rem; } .md-typeset { color: var(--docs-text-secondary); font-size: 1rem; line-height: 1.7; } -/* Offsets anchor jumps (TOC links, in-page #hash links) so headings don't land - under the sticky header. Scoped to headings rather than a page-wide - scroll-padding-top on , which also caught focus() calls on elements - inside the header itself and caused a large scroll jump on search open. */ -.md-typeset h1, .md-typeset h2, .md-typeset h3, .md-typeset h4, .md-typeset h5, .md-typeset h6 { scroll-margin-top: 5rem; } +/* Offsets anchor jumps (TOC links, in-page #hash links) so the target doesn't + land under the sticky header. Scoped to elements inside the content rather + than a page-wide scroll-padding-top on , which also caught focus() + calls on elements inside the header itself and caused a large scroll jump + on search open. Matches any [id], not only headings, so list items, tables + and other targets are covered. The values are the header's height plus a + little air: the header is ~61px alone and ~109px with the tabs row, which + shows from 76.25em (the same breakpoint responsive.css uses). */ +.md-typeset [id] { scroll-margin-top: 5rem; } +@media screen and (min-width: 76.25em) { .md-typeset [id] { scroll-margin-top: 8rem; } } .md-typeset h1, .md-typeset h2, .md-typeset h3, .md-typeset h4, .md-typeset h5 { color: var(--docs-text); font-weight: 700; letter-spacing: -.025em; } .md-typeset h1 { margin: 0 0 1.5rem; font-size: 1.875rem; line-height: 1.25; } .md-typeset h2 { margin-top: 3rem; padding-top: .25rem; font-size: 1.5rem; line-height: 1.35; }