In our new tutorial we’ll create a new nice multicolor and crossbrowser CSS3 menu with sliding (I use css3 transition) and color pure css3 color switcher. This is UL-LI-based menu.
Here are samples and downloadable package:
Ok, download the example files and lets start coding !
Step 1. HTML
As usual, we start with the HTML. Here are full html code of our menu. As you can see – this is multilevel menu built on UL-LI elements. But, it is a little unusual. I don’t wrap submenus into own UL element, I am going to hide them, and display if necessary.
index.html
04 | <meta charset="utf-8" /> |
05 | <title>CSS3 multicolor menu | Script Tutorials</title> |
06 | <link href="css/styles.css" rel="stylesheet" type="text/css" /> |
07 | <link href="css/menu.css" rel="stylesheet" type="text/css" /> |
11 | <h2>CSS3 multicolor menu</h2> |
14 | <div class="container"> |
16 | <span id="red"></span> |
17 | <span id="orange"></span> |
18 | <span id="pink"></span> |
19 | <span id="green"></span> |
20 | <span id="blue"></span> |
21 | <span id="indigo"></span> |
22 | <span id="violet"></span> |
23 | <span id="grey"></span> |
25 | <div class="colorScheme"> |
26 | <a href="#red" class="red"></a> |
27 | <a href="#orange" class="orange"></a> |
28 | <a href="#pink" class="pink"></a> |
29 | <a href="#green" class="green"></a> |
30 | <a href="#blue" class="blue"></a> |
31 | <a href="#indigo" class="indigo"></a> |
32 | <a href="#violet" class="violet"></a> |
33 | <a href="#grey" class="grey"></a> |
38 | <li><a class="hsubs" href="#">Menu 1</a> |
40 | <li><a href="#">Submenu 1</a></li> |
41 | <li><a href="#">Submenu 2</a></li> |
42 | <li><a href="#">Submenu 3</a></li> |
43 | <li><a href="#">Submenu 4</a></li> |
44 | <li><a href="#">Submenu 5</a></li> |
47 | <li><a class="hsubs" href="#">Menu 2</a> |
49 | <li><a href="#">Submenu 2-1</a></li> |
50 | <li><a href="#">Submenu 2-2</a></li> |
51 | <li><a href="#">Submenu 2-3</a></li> |
52 | <li><a href="#">Submenu 2-4</a></li> |
53 | <li><a href="#">Submenu 2-5</a></li> |
54 | <li><a href="#">Submenu 2-6</a></li> |
55 | <li><a href="#">Submenu 2-7</a></li> |
56 | <li><a href="#">Submenu 2-8</a></li> |
59 | <li><a class="hsubs" href="#">Menu 3</a> |
61 | <li><a href="#">Submenu 3-1</a></li> |
62 | <li><a href="#">Submenu 3-2</a></li> |
63 | <li><a href="#">Submenu 3-3</a></li> |
64 | <li><a href="#">Submenu 3-4</a></li> |
65 | <li><a href="#">Submenu 3-5</a></li> |
68 | <li><a href="#">Menu 4</a></li> |
69 | <li><a href="#">Menu 5</a></li> |
70 | <li><a href="#">Menu 6</a></li> |
Step 2. CSS
Here are the CSS styles of our menu. Maybe you’ve noticed – that in our html – I have two CSS files: layout.css and menu.css. The first file (layout.css) contain the styles of our demo page. We will not publish these styles in this article, but if you wish – you can find these styles in our package.
002 | list-style: none outside none; |
007 | background-color: #000000; |
008 | border-radius: 5px 5px 5px 5px; |
009 | box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.5); |
015 | background-color: red; |
016 | border:1px solid red; |
017 | border-radius: 0 5px 5px 5px; |
018 | border-width: 0 1px 1px; |
019 | box-shadow: 0 5px 5px rgba(0, 0, 0, 0.5); |
022 | padding: 20px 0 10px; |
026 | -moz-transform: scaleY(0); |
027 | -ms-transform: scaleY(0); |
028 | -o-transform: scaleY(0); |
029 | -webkit-transform: scaleY(0); |
030 | transform: scaleY(0); |
032 | -moz-transform-origin: 0 0; |
033 | -ms-transform-origin: 0 0; |
034 | -o-transform-origin: 0 0; |
035 | -webkit-transform-origin: 0 0; |
036 | transform-origin: 0 0; |
038 | -moz-transition: -moz-transform 0.1s linear; |
039 | -ms-transition: -ms-transform 0.1s linear; |
040 | -o-transition: -o-transform 0.1s linear; |
041 | -webkit-transition: -webkit-transform 0.1s linear; |
042 | transition: transform 0.1s linear; |
053 | text-decoration: none; |
056 | background-color: red; |
057 | border-radius: 5px 5px 5px 5px; |
060 | #nav li:hover > a.hsubs { |
061 | border-radius: 5px 5px 0 0; |
063 | #nav li:hover ul.subs { |
068 | -moz-transform: scaleY(1); |
069 | -ms-transform: scaleY(1); |
070 | -o-transform: scaleY(1); |
071 | -webkit-transform: scaleY(1); |
076 | #nav ul li:hover > a { |
077 | background-color: #222222 !important; |
078 | border-radius: 5px 5px 5px 5px; |
084 | list-style: none outside none; |
096 | background-color: red; |
098 | .colorScheme .orange { |
099 | background-color: orange; |
102 | background-color: pink; |
104 | .colorScheme .green { |
105 | background-color: green; |
108 | background-color: blue; |
110 | .colorScheme .indigo { |
111 | background-color: indigo; |
113 | .colorScheme .violet { |
114 | background-color: violet; |
117 | background-color: grey; |
120 | #red:target ~ #nav ul { |
121 | background-color: red; |
122 | border: 1px solid red; |
124 | #orange:target ~ #nav ul { |
125 | background-color: orange; |
126 | border: 1px solid orange; |
128 | #pink:target ~ #nav ul { |
129 | background-color: pink; |
130 | border: 1px solid pink; |
132 | #green:target ~ #nav ul { |
133 | background-color: green; |
134 | border: 1px solid green; |
136 | #blue:target ~ #nav ul { |
137 | background-color: blue; |
138 | border: 1px solid blue; |
140 | #indigo:target ~ #nav ul { |
141 | background-color: indigo; |
142 | border: 1px solid indigo; |
144 | #violet:target ~ #nav ul { |
145 | background-color: violet; |
146 | border: 1px solid violet; |
148 | #grey:target ~ #nav ul { |
149 | background-color: grey; |
150 | border: 1px solid grey; |
153 | #red:target ~ #nav li:hover > a { |
154 | background-color: red; |
156 | #orange:target ~ #nav li:hover > a { |
157 | background-color: orange; |
159 | #pink:target ~ #nav li:hover > a { |
160 | background-color: pink; |
162 | #green:target ~ #nav li:hover > a { |
163 | background-color: green; |
165 | #blue:target ~ #nav li:hover > a { |
166 | background-color: blue; |
168 | #indigo:target ~ #nav li:hover > a { |
169 | background-color: indigo; |
171 | #violet:target ~ #nav li:hover > a { |
172 | background-color: violet; |
174 | #grey:target ~ #nav li:hover > a { |
175 | background-color: grey; |
Conclusion
Hope you enjoyed with new menu, don’t forget to tell thanks and leave a comment
Good luck!