11

We currently have the problem, that links in the form www.example.com/#section don't jump to the right location, because we have a fixed navigation at the top which covers up the first part of the website.

<div id="anchorpoint">Some content here</div>

How can we tell the browser to jump to the anchor position + 100px?

Thank you.

Simon Ferndriger
  • 4,455
  • 6
  • 28
  • 53
  • possible duplicate of [Fixed position navbar obscures anchors](http://stackoverflow.com/questions/9047703/fixed-position-navbar-obscures-anchors) – Telmo Marques May 10 '14 at 12:41
  • 1
    The only solution without involving JS and repositioning your elements is to put the anchor point inside the element you want to scroll to, make it absolute, give it a 100px top margin and hide it. That way, you'd actually scroll to that invisible element, making the wanted element appear right at the top. – Shomz May 10 '14 at 12:42
  • @TelmoMarques You are right about the question. However, the answers are not satisfying there – Simon Ferndriger May 10 '14 at 13:37
  • 1
    @Shomz It works, but ONLY if you DON'T position it absolute – Simon Ferndriger May 10 '14 at 13:38

2 Answers2

21

HTML (add an additional anchor tag)

 <a id="anchorpoint" class="anchor"></a>
 <div>Some content here</div>

CSS

.anchor {
    display:block;
    padding-top:100px;
    margin-top:-100px;
 }

It's a slight modification of Fixed position navbar obscures anchors. The advantage lies there, that you don't prepopulate padding and margin of the actual container.

Community
  • 1
  • 1
Simon Ferndriger
  • 4,455
  • 6
  • 28
  • 53
3

This worked for me:

<a href="#learnmore"><button type="button" class="large button">Click me!</button></a>
<a class="hidden-anchor" name="learnmore"></a>

And the css for the anchor link.

 .hidden-anchor {
    position: absolute;
    top: -100px;
 }
Maximus
  • 1,417
  • 15
  • 19