Recently, I have been busy working on several mobile applications – both web and native apps. Most of them was User Centric and app was allowing them to set their own themes. This made my job as a CSS Developer a little trickier as I was using several icons with CSS sprites. Trying to come up with a better solution on how can I get rid of limited opportunity given by image sprites – I made a decision that CSS Icon should play the role here.
Here is why I chose to do the same:
- Very first, it’s very best for performance as there wont be any HTTP request and
- CSS icons are modular – we can reuse and remake/style it based on condition.
Today, I am going to share some of very basic icons – that we can create using CSS and use it right away- the way we wanted. This is a series of posts, will be posting more on coming days – more icons with CSS.
Mean time, you can check CSS3 Document Icon, written by me for Nettus+.
Above preview, if you try to produce by using image icon – you gotta use 4 different images. But if you write by CSS, NO IMAGE is required. Even if you need to change the color and you did use image, you will need another set of images with color changed in Photoshop and reusing – causing bit more load to your page. By CSS – you can have as many colors as your want – much more efficient, efficient – that’s why I called it – CSS Icons for better web.
How to - Steps:
- A simple class with border on right & top – no background.
- Then Rotate it to different angles (45 for right, 135 for down, 225 for left and -45 for up.)
Lets Do it.
1. Any Element with Class .arrow
<i class="arrow"> </i>
border-top:3px solid #aaa;
border-right:3px solid #aaa;
Now create three more classes with different different rotation and apply to HTML along with the main class.
Changing the arrow color on HOVER, (See how easy – think what we used to do with images):
You can see the final preview here (See in Result Tab):
And Here is a useful demonstration, (using :after pseudo element instead of separate HTML element to keep markup clean and more semantic) (See in Result Tab):