Anchor Link Edge or Positioning

Asked

Viewed 1,235 times

1

I have an anchor link that takes a button at the top to a certain part of the page, but as my menu accompanies the page, it ends up being cut as in the image below:

inserir a descrição da imagem aqui

How would I give a space? Margin or position, I don’t know, but I need the link to go down so it looks like this:

inserir a descrição da imagem aqui

I’m using a script to smooth the scrolling:

    <script type="text/javascript">
    jQuery(document).ready(function($) { 
        $(".scroll").click(function(event){        
            event.preventDefault();
            $('html,body').animate({scrollTop:$(this.hash).offset().top}, 800);
       });
    });
    </script>
  • 2

    Put a + 20 after the .top. scrollTop:$(this.hash).offset().top + 20

  • show @Zoom, it worked perfectly, I only put negative value, because the positive went up even more, but the solution was perfect! Thanks!

  • So it was negative. Always confusing... Rsrsrs

  • 1

    Hello. @Zoom enter answer to get answered :)

2 answers

1

If you want to achieve the same result using CSS only, just add the following to your style.css or custom.css

:target:before {
content:"";
display:block;
height:90px; /* fixed header height*/
margin:-90px 0 0; /* negative fixed header height */
}

Where the 90px is the spacing you want

1


Put a - 20 after . top.

scrollTop:$(this.hash).offset().top - 20 

So it positions -20 pixels of your element.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.