Forum Moderators: open

Message Too Old, No Replies

Vertically centering an anchor tag

How do you center something vertically on the page

         

frankly

1:24 am on Mar 8, 2005 (gmt 0)

10+ Year Member



Hello. I'm new to this forum and have been stumped on this problem for a while now. I am hoping that it is possible. I'm looking to load a specific part of the page in the center of a user's browser when they go to the page.

For example, if a user navigates to
[example.com...]
it will load example.htm and then scroll/center the 'thisanchor' anchor in the center of the page.

Normally it will adjust the page so #thisanchor will appear at the very top of the screen but I want this to be in the center of the screen. Is this possible?

[edited by: tedster at 1:47 am (utc) on Mar. 8, 2005]
[edit reason] use example.com [/edit]

zollerwagner

4:04 am on Mar 9, 2005 (gmt 0)

10+ Year Member



I don't know of a way to do it with precision. But what if you just put the anchor a little further up the page, a distance that would be approximately 300px up?

Just curious: Why would you want to do this?

tedster

5:36 am on Mar 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I often take the approach that zollerwagner suggests - when doing usability observations, I've noticed that for some pages the user has trouble spotting what they want when the named anchor takes them to a line that is right against the top of the window. Their eye does not immediately focus on the edge as a "hot spot."

However, placing a named anchor in the exact vertical middle of the window would be more of a challenge. I have thought about it, but decided it wasn't worth the trouble - since browser windows come in so many possible sizes. One approach ould be using javascript to find the vertical middle of the window.

The script would capture availHeight, and then scroll the page an additional amount of half that number.

frankly

12:00 am on Mar 17, 2005 (gmt 0)

10+ Year Member



Sorry for the long delay in a response. Thanks for your input.

I'd considered just placing the actual anchor a few lines up so that it will 'appear' vertically centered on the page but my page will start to get very complicated. (it's a dynamically generated page)
Plus it will probably have some issues at the edges of my list.

I was hoping there would be an easy solution to the problem that I have overlooked. Thanks for your input though. I agree that it'll most likely be more trouble for what it's worth.