If I have a non-scrolling header in an HTML page, fixed to the top, having a defined height:
Is there a way to use the URL anchor (the #fragment
part) t
I needed something that works for inbound links, links on page, AND that can be targeted by JS so the page can respond to changes in the header height
HTML
...
Who?
...
Can I be clicked?
What?
...
When?
CSS
.fragment-target {
display: block;
margin-top: -HEADER_HEIGHTpx;
padding-top: HEADER_HEIGHTpx;
z-index: -1;
}
The z-index: -1
allows links in the 'padding area' above a fragment-target to still be clickable, as commented by @MuttenXd on his answer
I haven't found an issue yet in IE 11, Edge 15+, Chrome 38+, FF 52+, or Safari 9.1+