Skip to content

Commit

Permalink
Merge pull request #264 from ucsc/fix/UCSC-130/anchor-links-scroll-of…
Browse files Browse the repository at this point in the history
…fset

[UCSC-130] Prevent sticky header from covering scroll targets
  • Loading branch information
bjcooper authored Sep 7, 2023
2 parents 4246f74 + dbbdbfb commit edb3046
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/js/components/main-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ const deactivateMenuItem = ( data ) => {

const handleResize = () => {
// Find the site header height.
const siteHeader = document.querySelector( '.site-header__header' );
const siteHeader = document.querySelector( '.site-header' );
document.documentElement.style.setProperty(
'--site-header-height',
siteHeader.clientHeight + 'px'
Expand Down
7 changes: 7 additions & 0 deletions src/scss/theme-regions/_site-header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@
}
}

// Add a top scroll margin to scroll targets in other regions so they're not
// behind the sticky nav after being scrolled to.
.content-region *,
.footer-region * {
scroll-margin-top: calc(var(--site-header-height, 0) + 1rem);
}

////////////////////////////////////////////////////////////////////////////////
// Site Header Template
////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit edb3046

Please sign in to comment.