Today I’m going to show you how to create a flashy menu using CSS3.
This tutorial is for beginners and can be completed fairly quickly. Make
sure you click on the link below to see a demo of the menu and get the
source code.
Download the Demo & Source
Final result:
The HTML
Our HTML document contains an unordered list and each list item is a
link with an anchor tag. The span contains the name of the menu item.
2 | < li >< a href = "#" >< span >Home</ span ></ a ></ li > |
3 | < li >< a href = "#" >< span >Article</ span ></ a ></ li > |
4 | < li >< a href = "#" >< span >Blog</ span ></ a ></ li > |
5 | < li >< a href = "#" >< span >Gallery</ span ></ a ></ li > |
6 | < li >< a href = "#" >< span >About</ span ></ a ></ li > |
7 | < li >< a href = "#" >< span >Contact Us</ span ></ a ></ li > |
8 | < li >< a href = "#" >< span >Alumini</ span ></ a ></ li > |
9 | < li >< a href = "#" >< span >Portfolio</ span ></ a ></ li > |
The CSS
I am using a pattern for our page background from
SubtlePatterns.
2 | background : #eee url (../images/white_paperboard.png) repeat top right ; |
Now let’s position menu list items. I am using 25% width for each
item, so in each row four menu items can be positioned. I’m aligning
text of each list item to center.
Next let’s position each anchor tag and change text decoration to
none. I am using a light gray color background. I am also adding
CSS3 transition effects to these elements with a duration of one second.
10 | background-color : rgba( 164 , 164 , 164 , 0.2 ); |
11 | -webkit-transition: all 1 s; |
12 | -moz-transition: all 1 s; |
13 | -o-transition: all 1 s; |
I am using ‘Kotta One’ font for span text, normal font size and
weight of 20px and 700 respectively. I’ve made the font color for the
text in its hover state white.
6 | color : rgba( 120 , 120 , 120 , 0.9 ); |
7 | text-transform : uppercase ; |
8 | font-family : 'Kotta One' , serif ; |
11 | .main-ul li:hover span{ |
Here comes our main part, I have already added transition effect for
the anchor tags. Now add hover effects for each anchor tag list item by
changing its background color. So when someone hovers over each list
menu item it will change background color to a new color. I’m also
adding
CSS3 transform rotate effects of 3 degrees.
1 | .main-ul li:nth-child( 1 ):hover a{ |
2 | background-color : rgba( 175 , 54 , 55 , 0.8 ); |
3 | -moz-transform: rotate( -3 deg); |
4 | -webkit-transform: rotate( -3 deg); |
5 | -o-transform: rotate( -3 deg); |
6 | transform: rotate( -3 deg); |
Now repeat the above step for all list items with a new background color of your choice!
1 | .main-ul li:nth-child( 2 ):hover a{ |
2 | background-color : rgba( 199 , 204 , 73 , 0.8 ); |
3 | -moz-transform: rotate( -3 deg); |
4 | -webkit-transform: rotate( -3 deg); |
5 | -o-transform: rotate( -3 deg); |
6 | transform: rotate( -3 deg); |
8 | .main-ul li:nth-child( 3 ):hover a{ |
9 | background-color : rgba( 213 , 135 , 11 , 0.8 ); |
10 | -moz-transform: rotate( 3 deg); |
11 | -webkit-transform: rotate( 3 deg); |
12 | -o-transform: rotate( 3 deg); |
13 | transform: rotate( 3 deg); |
15 | .main-ul li:nth-child( 4 ):hover a{ |
16 | background-color : rgba( 51 , 143 , 144 , 0.8 ); |
17 | -moz-transform: rotate( 3 deg); |
18 | -webkit-transform: rotate( 3 deg); |
19 | -o-transform: rotate( 3 deg); |
20 | transform: rotate( 3 deg); |
22 | .main-ul li:nth-child( 5 ):hover a{ |
23 | background-color : rgba( 117 , 18 , 98 , 0.8 ); |
24 | -moz-transform: rotate( -3 deg); |
25 | -webkit-transform: rotate( -3 deg); |
26 | -o-transform: rotate( -3 deg); |
27 | transform: rotate( -3 deg); |
29 | .main-ul li:nth-child( 6 ):hover a{ |
30 | background-color : rgba( 33 , 136 , 215 , 0.8 ); |
31 | -moz-transform: rotate( -3 deg); |
32 | -webkit-transform: rotate( -3 deg); |
33 | -o-transform: rotate( -3 deg); |
34 | transform: rotate( -3 deg); |
36 | .main-ul li:nth-child( 7 ):hover a{ |
37 | background-color : rgba( 109 , 109 , 109 , 0.8 ); |
38 | -moz-transform: rotate( 3 deg); |
39 | -webkit-transform: rotate( 3 deg); |
40 | -o-transform: rotate( 3 deg); |
41 | transform: rotate( 3 deg); |
43 | .main-ul li:nth-child( 8 ):hover a{ |
44 | background-color : rgba( 152 , 120 , 92 , 0.8 ); |
45 | -moz-transform: rotate( 3 deg); |
46 | -webkit-transform: rotate( 3 deg); |
47 | -o-transform: rotate( 3 deg); |
48 | transform: rotate( 3 deg); |
That’s it, we have accomplished a simple flashy menu, so that when
someone hovers over our menu items simultaneously it will change
background color and slightly rotate. Thanks for reading!
No comments: