How to add icons using CSS Attribute Selector?

CSS Attribute Selector
CSS Attribute selectors are very powerful giving you many options to control styles of different elements e.g. you can add an icon based on the href attribute of the a tag to let the user know whether link points to an image, pdf, doc file etc.

Supported Browsers
IE7/IE8/IE9/Mozilla/Safari/Opera/Chrome.

CSS Code
a[href$=’doc’]
{
padding:5px 0 5px 30px;
background:url(doc_icon.png) no-repeat left center;
font:normal 14px arial;
line-height:32px;
}

HTML Code
<a href=”example.doc”>Doc File</a>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s