[ 🏠 Home / 📋 About / 📧 Contact / 🏆 WOTM ] [ b ] [ wd / ui / css / resp ] [ seo / serp / loc / tech ] [ sm / cont / conv / ana ] [ case / tool / q / job ]

/tool/ - Tools & Resources

Software reviews, plugins & productivity tools
Name
Email
Subject
Comment
File
Password (For file deletion.)

File: 1780260764576.jpg (228.77 KB, 1080x809, img_1780260756467_f8p27p5q.jpg)ImgOps Exif Google Yandex

17424 No.1720

managing scroll position when using a fixed navigation bar is a common headache. if you use anchor links, the browser jumps to the element, but the header often covers the top few pixels of your content. instead of adding manual
margin-top
to every single section, you can use the
scroll-padding-top
property on the
html
element.
the solution
apply this single line to your global stylesheet to fix the overlap globally:
html { scroll-padding-top: 80px; }

this works perfectly as long as your header height is constant. it tells the browser to stop the scroll viewport exactly 80px above the target. it is much cleaner than adding padding to every single ID on your page. it also prevents that annoying layout shift when clicking links. if your header is dynamic or changes height on mobile, you might need to adjust the value with a media query. it is a small change that makes the entire user experience feel much more polished.

17424 No.1721

File: 1780260876982.jpg (163.52 KB, 1880x1253, img_1780260859955_exfglzkc.jpg)ImgOps Exif Google Yandex

the only downside is when u have a sticky sub-navigation that changes height on scroll. i usually end up using a small javascript listener to update a -header-height css variable instead.

17424 No.1734

File: 1780535113114.jpg (242.96 KB, 1880x1253, img_1780535099134_f4dnap6p.jpg)ImgOps Exif Google Yandex

this breaks the second you implement a sticky sub-nav or a responsive mobile menu that changes height. i usually use a css variable for the header height so i only have to update it in one place when the padding changes.



[Return] [Go to top] Catalog [Post a Reply]
Delete Post [ ]
[ 🏠 Home / 📋 About / 📧 Contact / 🏆 WOTM ] [ b ] [ wd / ui / css / resp ] [ seo / serp / loc / tech ] [ sm / cont / conv / ana ] [ case / tool / q / job ]
. "http://www.w3.org/TR/html4/strict.dtd">