On page 1 there is a link which takes you to a certain point on page 2
<a href="page2.html#position">MY TEXT HERE</a>
This takes you straight to the anchor (position) on page 2 with the following code
<a name="position"> MORE TEXT HERE</a>
Now, my question is how can I change the text and background color when #position is in the URL?
For example: www.domainname.com/page2.html#position
This is the CSS I used but doesn't work:
#position {
color:#ff0000;
background-color:#f5f36e;
}
Here is a example http://jsfiddle.net/jvtcj/2/
Thank you in advance!
Use the :target
selector:
a:target, /* or simply */
:target {
/* CSS to style the focused/target element */
}
You'd be better off using the id
of a particular element to receive the focus, since named-anchors seem to have been dropped, if not deprecated entirely.
References:
You can use the CSS3 :target
peseudo selector: http://blog.teamtreehouse.com/stay-on-target
Also, don't use the old myth <a name="destination">...</a>
, all you need is to id
the section you want to jump to, e.g. <section id="destination">...</section>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With