tags:

views:

35

answers:

1

I want to link to a section of a page using a bookmark site.com/Page.htm#Bookmark)

When the page is rendered, I'd like to highlight everything within the #Bookmark (Anchor)

E.g.,

Employee 1 , blah blah <---this text would be highlighted.

Naturally there are a dozen or so different bookmarks.

I was thinking maybe I could assign a CSS style to the Active link state or something similar.

Any ideas?

+3  A: 

You can do this with the :target selector:

http://www.w3.org/TR/css3-selectors/#target-pseudo

Example: http://www.mysite.com/#foo

<div id="foo">Here is a message</div>

#foo:target {
    background: yellow;
}

More info: http://carsonified.com/blog/features/css/stay-on-target/

Unfortunately it does not work in IE6/7.

Ryan Doherty
+1 I had never heard of that before.
Josh Leitzel
That's a slick idea, although all the examples on the Carsonified.com website are 404 links. I really need something that's going to work for a good 80% or more browsers.
Clay Nichols
If you need support in all browsers, you'll have to use some JS to grab hash (document.location.hash), then find the element in the DOM with that ID and add a 'highlight' classname to it. Then you can style appropriately.
Ryan Doherty