Offsetting Anchors to Adjust for Fixed Headers
When a fixed header is present on a webpage, clicking on an anchor below it results in the page jumping so that the anchor is aligned with the top of the page. This can obscure content that may need to be referenced concurrently.
Solution: HTML/CSS Offset Technique
To address this issue, you can offset the anchor's position using CSS:
Assign a class to the anchor:
<a class="anchor">
Convert the anchor to a block element and relatively position it:
a.anchor { display: block; position: relative; }
Apply a negative offset to move the anchor above its actual position:
a.anchor { top: -250px; }
This offset value should be adjusted based on the height of your fixed header to ensure the anchor aligns correctly with the content's position on the page.
The above is the detailed content of How Can I Adjust Anchors to Account for Fixed Headers?. For more information, please follow other related articles on the PHP Chinese website!