Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Anchor links scroll to incorrect position

I'm struggling to make my anchor links work properly. Website is http://www.imprero.com and at the very top you see a link "Zobacz atrakcje" which should lead to a section below called "Produkty". Here already the scroll positions the window too much upward, since all two icon rows should be visible (according to div id="produkty"). Now this is the product list linked internally to sections of the page below. Only the first two position correctly, whereas all further are more or less wrong. In each product section there is a link "Lista atrakcji" which directs back to the product list. When I click the same icon link it many times directs me to a slightly different position. What the heck??? Any ideas? Would appreciate...

like image 377
Chris Osiak Avatar asked Oct 14 '25 04:10

Chris Osiak


1 Answers

The problem is that your fixed header is out of the document flow so it's height/position are not factored in to the scroll position of the browser. If you were to hide the header after clicking the anchor tag you would see that it does place you in the right position. This can be compensated for with a little CSS:

// Adjustment for anchor tag positioning with fixed header
:target:before
{
   content: "";
   display: block;
   height: 57px; //Height of header
   margin-top: -57px;
}
like image 53
dukedevil294 Avatar answered Oct 18 '25 07:10

dukedevil294



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!