Get Latest Tricks Alert Daily
Follow Readers

Add Icons Next To Hyperlinks Using CSS3


SHARE:


Hyperlink-IconsCascading Style Sheet is the heart of designers and with latest web technology such as CSS3, designing has become even more interesting. Thanks to CSS3 attribute value selectors, now you can style any file extension or tag.
I am using CSS3 attribute selector property in this tutorial to add Icons to hyperlinks.Previously we had to
use JavaScript to add an icon next to the hyperlink on your blogger blog or website but now you can do it easily using CSS3. The icon will depend upon the type of file extension. If your link is pointing to a mp3 file then it will add a music symbol next to the link and so on. See the demo which shows 13 file format links,

Live Demo


How To Add Icons to Hyperlinks in Blogger?

  1. Go To Blogger > Design>  Edit HTML
  2. Check the "Expand Widget Templates" Box
  3. Search for this,
]]></b:skin>
     4.  Just above it paste the code given below,
/*--------- MBT Hyperlink Icons ----------*/
a[href*='.js'] {
background: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVJrbqwrvsVusPH4XXpyc262ydr_lXHpEuDgUyvlQp5FjMHfVnnol8AcwCOfg8dG_d-zP8p4mIWustt4GxtjovMoypseeDxen0bSpakh7bAEfw130PUig8mPTnX-OFF79wdG61eNITmDk/s400/file_js.png) no-repeat 0 0;
padding:7px 0 0 25px;
}
a[href*='.gif'] {
background: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3uKh2LS81PNeY7qQTHLm3K7YAHct29U7nsAFiJWUk6a2vpX0A-5ZYJACDiTu1gBNZfb479ts_GYTT9b7hV35o5RLoJoPAnGlpR_f3n1MOyQMUg_7KvlpEJ-J6uRPYBxHvtSQ78Bp85lo/s400/file_gif.png) no-repeat 0 0;
padding:7px 0 0 25px;
}
a[href*='.doc'] {
background: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAq1mUghWEyFmqEElkxVG-dYplh5FPBkQum3xT6aUgggZIEzdLGeDyIQF_ujyj7Lsu-lOndw5cCbKEZajnRBMq0DBRStXoQJ5LGNq0PuKKaiGpNBlq7FwvEWPR3lZyKoh0jGmf620dz2E/s400/file_doc.png) no-repeat 0px 0px;
padding:7px 0 0 25px;
}
a[href*='.rar'] {
background: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzXisHnecJSM1FMAeizYQOvcSGNuErP9O-4RJzjBfun_wsVwSn5xOLnxQx6p8bKImKp215XMRMroGMSxZUeP0ubulBp3KbKwLl-kXn8Moa38-pBqDCBSppeXx78QFe_5MRUg-YncwkJbY/s400/file_rar.png) no-repeat 0px 0px;padding:7px 0 0 25px;
}
a[href*='.zip'] {
background: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6_9bVokTac7JTU7HxGVtvIGRrMoU2r6whugbBKxEY-NwYEL3VHv_OOfn469-OblWaGBqjoidcFoOyV5WN500gw6l1EKfST3rYPJXF9EpsW75PkCbcFgHnzDIOzkY9ai1jMHAhsko5Gyw/s400/file_zip.png) no-repeat 0px 0px;
padding:7px 0 0 25px;
}
a[href*='.mp4'] {
background: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-tRZlg3vfuGspLiUAzg9P40lugC30dG7GdAl3VW6mb450Uh_RVZxJ-chJtOCH-MURIOoHQt00Pu8wKFspXi9zFOEQHaExjidWSSZW21tVTadgNhImsSevcnsnwlIjIFWogx7sZQab740/s400/file_mp4.png) no-repeat 0px 0px;
padding:7px 0 0 25px;
}
a[href*='.php'] {
background: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQohv6Gaai3O-CEpAYiFqb554k1TMHU_MSez8tfXZKGcRThCefoi_ca4vzgl6ZNrT4WEqL8q5rrDgTgACPJf5qJasVkfYLeksJFSzs3YSD5ZnEehBaTceyKFdIm_aYS7odW7Z8xWdFUeU/s400/file_php.png) no-repeat 0px 0px;
padding:7px 0 0 25px;
}

a[href*='.xml'] {
background: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6A1GBQTEZr9KMlim1wR6R6r_xJGuxkm20I5gle0AHQ9ou3g5874ZBTWXzc-eb1ggPTIfpyasU-ffr5CRcLnCcUCwNMWWnyYv-elQZQL6pNqLhsYz4EM8kjfQ_iCGjVdNqmegjl73YJMg/s400/file_xml.png) no-repeat 0px 0px;
padding:7px 0 0 25px;
}
a[href*='.pdf'] {
background: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfr3iY6Em5FTHkXnRz3sd4GPdBRZ37iNpVF_Gvy0q0ErThVkcWX0j7_M2W9mEmNfMJvhbUTlB1hv5T_vi3ZZuZVRfG71TCDdyf5aGxp4rVI2aLWQGZBdjeuVXHjTXNItm-TYU9VtGDZAQ/s400/file_pdf.png) no-repeat 0px 0px;
padding:7px 0 0 25px;
}
a[href*='.xls'] {
background: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhown7uF3kKP3wUyzI_2RRShHSbbYO_gZtkHXUehYGP8AL8LXtXp8J7T0lQDnZqnDHZLRH6sgEpMYD6dCYO7mahyphenhyphenGzHIsx8lB4k0MdmMbvgpj3eMsX-2mZxTPvuR98uKHsmi0jyN364dAo/s400/file_xls.png) no-repeat 0px 0px;
padding:7px 0 0 25px;
}

a[href*='.mpg'] {
background: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBq1GEiWbG5SEIOPzmpBkb81lOmuph8857T8dhiCL9CRe-PE_pY7r9XhIL7oA3bc1WhySOYW-XCqDg49gXa-V4nyQ6DCINSfSSaWGPSa48zGmxAcyq26VCoz0c_ssRyehnlc1NeT6aDyA/s400/file_mpg.png) no-repeat 0px 0px;
padding:7px 0 0 25px;
}

a[href*='.bmp'] {
background: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEib_edtnMrRW1uSLbmvgU93bKoLcJ1i1XxweAlbJJ5ACPUJLLZqE7RuqIFEYQ7RSAeHPiqKI6qxQFV-DGKzNThezzJVOG4pnUPGwMpI8BALn1lQ3je97v-iUDMrUev79-zJZ4GOdT0PYfo/s400/file_bmp.png) no-repeat 0px 0px;
padding:7px 0 0 25px;
}

a[href*='.avi'] {
background: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSJuKCbk1cGwJugXKu2gQ0s7X1YZR7jSu3Ev-hR3VIJW1XXHaeOKGQrZ-AufC7hv0KubTnC5NVuMUmlelqnv2UAo6hamGSaS2nCLFHVMUfviOZumlN848f-bZSb3yh39J6Jki8KcDyivI/s400/file_avi.png) no-repeat 0px 0px;
padding:7px 0 0 25px;
}

a[href*='.mp3'] {
background: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0s4Q9jHilgT5sg83sBwaKrmFHlDxavTWxKyyuKEdYaY_clgKV2kf_YkzHMraefYUzzE5q7xym9bt1RKTuJ_9VjhSW0AdYZAPkHZC8VGIG6zvenjh42tGw2LH2ghlVWgyD0jfseCo5guc/s400/audio_alt.png) no-repeat 0px 0px;
padding:7px 0 0 25px;
}
a[href*='mailto'] {
background: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiiML7B3DiHanQMKBM6IY44HGKGUN3u4AfjUwClr7BOer0SXjqE2DpOo9P2AX40iTjJw3HWAnP84-wImVXfPspKrustKO5iJuoqrrvh7dgXH5w2e8a1bAiHhIpRrc2UhrJKdCjy4CRs4xA/s400/e_mail.png) no-repeat 0px 0px;
padding:0 0 0 25px;
}

    4.   Save your templates and you are done!

How it works?

The icons appear when the file extension is detected in the link. For Example if I add a link to pdf file like this,
<a href="http://www.mmkdrocker.blogspot.com/xyz.pdf">Download E-book</a>
Then the link will appear like this when I publish it,
hyperlink-image
Now add any Ebook or any image link in your blogger posts, sidebars or footer anywhere you want and you will find cute icons appearing next to the link. You can also use icons of your choice by simply changing the icon image links  in the code above. The code is really easy to edit and I hope after having read so much of our tutorials you can at least edit this code. Have fun and let me know if you faced any problem. Enjoy! :)
PS: This technique is first bloggerized at MBT, any adoption of the code without attribution to MBT author will be taken as copyright violation.




SHARE:



If you enjoyed this post and wish to be informed whenever a new post is published, then make sure you subscribe to our regular Email Updates!

Subscribe To Get Latest Tricks On Email!

 

0 comments:

Confused? Feel free to ask

Your feedback is always appreciated. I will try to reply to your queries as soon as time allows.

Note:
1. To add HTML CODE in comments then please use our HTML Encoder
2. You can always Try the tutorial on our HTML Editor
3. Please do not spam Spam comments will be deleted immediately upon my review.

Regards,
MMKTricks