Alex Rivera | Logout

Changing default starting position of #anchor

Asked 2011-02-14T19:22:36.740
33

I have a URL with an anchor that is working as it should:

site.com/item/id#comment-233

When opened, the anchor will be positioned at exactly the top of the page.

How do I change the starting point? Let's say I want it to be 50px down from the top.

The reason I'm needing this is because I have fixed layers at the top of the page, so the comment is appearing overlapped behind the fixed header div.

Just in case, because of cross-browser compliance I prefer a solution that does not involve changing the container of the comment to fixed and positioning top minus the height of the header.

Edit
Report

1 Answer

10

This worked a treat for me, based on the above suggestion:

<a name="[my-anchor-name]" class="anchor"></a>

.anchor {
    position:relative;
    top:-30px; /* or whatever value you need */
}
answered 2012-02-23T09:31:13.227

Your Answer