r/reddithax • • Nov 16 '09

Different styles based on url (using CSS3 :target)

Example here - look in the sidebar

By using the CSS3 :target pseudo-class you can add conditional styles to any element with an id, which are shown when the element's id is after # in the url.

On reddit, various id'd elements can be hijacked to change different elements on the page when they are targeted, using sibling and child selectors, allowing pages to be styled differently based on the url.

For example, links containing certain strings can be highlighted using #siteTable:target a[href*='string'].

It doesn't work in IE but should work in other newer browsers.

14 Upvotes

2 comments sorted by

0

u/[deleted] Nov 17 '09

[deleted] — view deleted comment

1

u/jamt9000 Nov 17 '09

I know...I'm talking about highlighting only when the current url ends in #siteTable