Scroll to anchor with fixed header, content hidden behind header, margin and top padding not working
Asked Answered
E

3

8

I'm using smoothscroll.js to navigate my site. It stops on the correct anchor in Firefox, however in Chrome it passes the point on the first click of the link, and pushes the content to the top, hiding the content behind the page. then if you click it again, it aligns correctly. I've seen the problems on other sites as well. Curious to see if others have the same problem. Chrome seems to ignore any top padding or margin or positioning (example: top:20%;).

Erich answered 29/1, 2011 at 8:27 Comment(0)
N
2

I find this solution very easy and useful. You just need to add 1 line of CSS.

html {
    scroll-padding-top: 70px; /* height of sticky header, because the header hides the content when jumping to it */
}

original answer: https://stackoverflow.com/a/56467997

Nipha answered 22/7, 2023 at 17:34 Comment(0)
C
0

I used Local Scroll (JQuery) to do this.

It allows you to do a top offset

$.localScroll({
    offset: -100
});
Carrier answered 15/5, 2014 at 14:15 Comment(0)
L
-2

This may be due to a new wordpress theme using the header html5 element. I changed my header to a div, and it worked fine.

Lutanist answered 15/3, 2012 at 15:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.