Code Snippet
Style Links Depending on Destination
a[href^="http://"] {
/* fully valid URL, likely external link */
}
a[href="http://google.com"] {
/* link to specific website */
}
a[href^="/"], a[href^=".."] {
/* internal relative link */
}
a[href^="mailto:"] {
/* email link */
}
a[href$=".pdf"] {
/* PDF file */
}
a[href$=".doc"] {
/* Microsoft Word document */
}
a[href$=".mp3"] {
/* Music file */
}
a[href$=".zip"] {
/* Archive file */
}
Wow! This is really neat! I’m sure I’ve seen it before but you’ve displayed it in an easy-to-understand way!
I just have a couple of questions:
1) I imagine that ^ means “beings with”; does $ mean “ends with” or “includes this text somewhere”?
2) Full cross-browser support? IE?
Thanks!
$ is indeed “ends with” (“includes this text somewhere” is [attr*="textanywhere"])
IE7+ has support for it
http://www.quirksmode.org/css/contents.html (“Advanced [attr] selectors”)
This is pretty handy. I’ve been using this method for nearly two years now. I saw a couple of new things here though. Thanks for sharing!
For the “link to specific website”, would declaring google.com cover all subdirectories of google.com (ie: google.com/images, google.com/analytics etc?). Or would they need to be specifically declared?
DigWP
A book and blog co-authored by Jeff Starr and myself about the World's most popular publishing platform.
Quotes on Design
Design, like Art, can be an elusive word to define and an awfully fun thing to have opinions about.
HTML-Ipsum
One-click copy to clipboard access to Lorem Ipsum text that comes wrapped in a variety of HTML.
Bookshelf
Hey Chris, what books do you recommend? These, young fertile mind, these.