There have been a few posts discussing similar issues (like offsetting an html anchor to adjust for fixed header), but none of the solutions seem to work for my specific situation.
I am currently using jQuery to generate a Table of Contents, following the method outlined in this article: http://css-tricks.com/automatic-table-of-contents/. The script looks for h2 tags within the article and creates anchor links accordingly.
The issue arises because I have a fixed header. When clicking on one of these anchor links, the target h2 is positioned underneath the header. A temporary fix I've implemented is:
h2:target{
padding-top:[header-height];
}
While this solution works when scrolling down, it causes a large gap in the content upon scrolling back up. Does anyone have suggestions on how I can adjust these anchor links to accommodate for the header? I would prefer to maintain semantic HTML structure. Any assistance would be greatly appreciated.
For reference, here's a jsFiddle demonstrating the issue I'm facing: http://jsfiddle.net/aweber9/GbNFv/
Thank you.