Skip to content

jameschen215/blog-frontend

Repository files navigation

Blog Project

What I've learned

scrollIntoView problem

When using a sticky header, scrollIntoView({ block: 'start' }) can cause target elements to be hidden beneath the header. Instead of relying on manual scroll offsets or layout hacks, the correct solution is to use CSS scroll offset utilities like scroll-margin-top. This approach keeps the layout intact, works naturally with sticky positioning, and results in a cleaner, more accessible scrolling experience.

Best fix(modern and clean):

.scroll-target {
  scroll-margin-top: 64px; /* header height */
}

Tailwind version (very common)

<!-- 16 = your header's height -->
<h2 class="scroll-mt-16">...</h2>

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages