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

14,980

SOLVED: http://nicolasgallagher.com/jump-links-and-viewport-positioning/demo/#method-D

There are several methods available.

Share:
14,980
Commandrea
Author by

Commandrea

Updated on July 22, 2022

Comments

  • Commandrea
    Commandrea almost 2 years

    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%;).

  • ATSiem
    ATSiem over 11 years
    I'm having trouble understanding how the #target in these methods correlates to the <a name="anchor"></a>. I was trying <a href="#target"></a> - like in the demo- but no go. Any tips?
  • David J.
    David J. over 9 years
    Nicolas Gallagher's methods are a bit complicated in comparison with stackoverflow.com/a/13184714/109618 which just involves this HTML <a class="anchor" id="label-1"></a> and this CSS: a.anchor{display: block; position: relative; top: -50px; visibility: hidden;}
  • dichterDichter
    dichterDichter almost 9 years
    i also think, after i tried several methods, that the hidden <a class="anchor"> is a very easy and nice solution. it gives you good control over the position of the linked element without destroying your normal layout where you can use margin and padding as you want. thx David James