Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to anchor to absolute top of the page with an anchor id such as #top

I have a toolbar at the top of my page with a fixed position, and I have anchors going to #top and #bottom.

The problem is, I know just href="#" will take the viewer to the absolute beginning of the page at the very top, however, I need it to be "#top" because of a jQuery script in place. When I place a div for #top right after the body tag, the anchor only takes me to the beginning of content on the page, not the actual top. The issue with this is that the toolbar is over it foreshadowing because of z-index, so it looks like it hasn't actually taken you to the top.

Is there any way I can get href="#top" to have the same effect as just href="#" directing to the very top of the page?

like image 685
popsicle Avatar asked Oct 30 '12 12:10

popsicle


1 Answers

Actually #top is already used by browsers to scroll to the top.. (just like #).

So if you do not have and element with id="top" then it will work as you want..

Demo at http://jsfiddle.net/gaby/AkAeD/1/

like image 146
Gabriele Petrioli Avatar answered Oct 09 '22 05:10

Gabriele Petrioli