Return to Snippet

Revision: 59272
at August 29, 2012 22:55 by skopp


Initial Code
/* external links
02
The ^= specifies that we want to match links that begin with the http://
03
*/
04
a[href^="http://"]{
05
    padding-right: 20px;
06
    background: url(external.gif) no-repeat center right;
07
}
08
 
09
/* emails
10
The ^= specifies that we want to match links that begin with the mailto:
11
*/
12
a[href^="mailto:"]{
13
    padding-right: 20px;
14
    background: url(email.png) no-repeat center right;
15
}
16
 
17
/* pdfs
18
The $= specifies that we want to match links whose hrefs end with ".pdf".
19
*/
20
a[href$=".pdf"]{
21
    padding-right: 20px;
22
    background: url(pdf.png) no-repeat center right;
23
}
24
/* zip
25
Same as above but for zip files and it adds an icon at the right of the link. Therefore the :after
26
*/
27
a[href$=".zip"]:after{
28
    content: url(icons/zip.png);
29
}
30
/* djavupixel
31
The *= specifies that at least one instance of the substring �djavupixel� matches.
32
*/
33
a[href *="djavupixel"] {
34
  padding-right: 17px;
35
  background: url(icons/super-star.png) no-repeat right;
36
}

Initial URL
http://www.djavupixel.com/development/css-development/master-css3-ultimate-css-code-snippets/

Initial Description
Style links depending on file format

Since CSS3 you can style links depending on some rules also called attribute selectors. This is extremely convenient if you have files in PDF, Zip among other and you want to display a small icon near it. With this technique you can do it without including an image on your link. This snippet shows a small icons next to your links telling the user if it is an external link, an email, a pdf, a zip or whatever you would like.

Initial Title
styling as per mime type / type of linked item

Initial Tags

                                

Initial Language
CSS