Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highlight linked headline

How can I add a CSS-class "highlight" to headlines or sections based on anchors like "...this.html#headline1" (e.g. the TOCs on Wikipedia).

This should also work when coming from a different page (href="http://mysite.com/this.html#headline1") and NOT only onclick like here: Highlight a # section in a page - jQuery

like image 417
Martin Avatar asked Nov 24 '25 14:11

Martin


1 Answers

In newer browsers, you can make use of the CSS3 :target pseudo selector.

*:target {
     background-color: #F5FFE1;
}

This does not work in IE 8 and below and not correctly in Opera.

like image 149
Felix Kling Avatar answered Nov 26 '25 05:11

Felix Kling



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!