I am reading CSS Mastery [the book] [the website] by Andy Budd at the moment. After reading the first chapters and a few other pages, I have already come across an interesting CSS usage that I should have been more aware of. The attribute selector is its name. To get to the point, the attribute selector allows you to style any web page element based on an attribute and, more interestingly, the attribute value (or partial value). In its simplest form the attribute selector and CSS code might be:
element[attribute] {CSS rule goes here} or
element[attribute="value"] {CSS rule goes here}
For example, the attribute selector will allow you to style all external links without modifying the HTML. This CSS code in your style sheet will give all external links a background color of yellow:
a[href^="http:"] {
background-color: #FF0;}
Cool. Well, perhaps not this shade of yellow (a background image is probably better), but you get the idea. In this case, the attribute selector, a[href^="http:"], selects all <a> elements with an href value starting with "http:". Of course, if you are using absolute links to your own site, you will need to add another rule for any links beginning with "http://www.yoursitename".
Other uses for the attribute selector might include styling document links (for example, PDF documents) and use with microformats.
At this point, I would normally be saying "except for Internet Explorer". However, newly released IE7 has support for the attribute selector. Great! It may be time to start using attribute selectors more.
More: How to use the attribute selector to block ads
Stunning CSS3: A Project-Based Guide: Use this book to work through a series of practical yet cutting-edge projects. Each chapter walks you through standalone exercises that you can integrate into projects you're working on, or use as inspiration.
» Buy from Amazon.com · Amazon.co.uk
ThemeForest sell a range of site templates from some fantastic designers. They also sell some great WordPress themes!
Online invoicing made easy with CurdBee!
» Sign up
Join SugarSync for online backup. Sync your files between Mac, PC and mobile phone. Get 5 GB FREE and up to 10 GB bonus space!
HTML5 and CSS3 for the Real World will show you how to create websites using these new methods.
This easy-to-follow guide covers everything you need to know to get started. You’ll master the new semantic markup available in HTML5, as well as how to use CSS3 without sacrificing clean markup or resorting to complex workarounds. Buy the Book! · FREE Chapters