PDA

View Full Version : Stop Anchor Links Jumping to top of browser window?


ccooper309155
07-21-2011, 11:06 PM
As we all know, when a hyperlink that is pointed at an Anchor is clicked, the page jumps to the Anchor's location, placing it right at the top of the browser window.

Here's the problem:

I'm using HTML 5 and CSS3. I have the <header> fixed via CSS. That is, when the page scrolls, the <header> stays fixed at the top of the page while the text in the <article> scrolls up under it and off the screen.

Trouble is, when an Anchor link is clicked, the Anchor shoots to the top of the browser and hides under the fixed <header>.

Yes, I could move the Anchors on the page so that they sit higher than the text with which they are associated, but that would be very, very time consuming in this case.

Is there another way to make the Anchors jump to a point about 100px below the top of the browser window instead of to the very top?

Thanks!

Ray Borduin
07-22-2011, 06:07 AM
I don't think there is a way to do this automatically with just an anchor link. You could replace the anchor link with javascript and then scroll the extra amount with the window.scrollBy() method: http://www.w3schools.com/jsref/met_win_scrollby.asp

ccooper309155
07-22-2011, 08:41 PM
Thanks Ray.

Found a CSS solution that works in IE and FF but not crappy Chrome:

Put each anchor in a div and apply a class that makes the div containing the anchor sit 100 pixels above where it ought to be.

Since the pages I'm working on will only be used by a few people, Google can go suck eggs!