In our new tutorial we’ll create a new nice CSS3 menu with interesting behavior, where I use css3 transition and animation. This is UL-LI-based multilevel 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 multilevel menu with transition and animation | Script Tutorials</title> |
06 | <link href="css/layout.css" type="text/css" rel="stylesheet"> |
07 | <link href="css/menu.css" type="text/css" rel="stylesheet"> |
11 | <h2>CSS3 multilevel menu with transition and animation</h2> |
14 | <div class="container"> |
17 | <a href="#">Parent link #1</a> |
18 | <a href="#">Sub #11</a> |
19 | <a href="#">Sub #12</a> |
20 | <a href="#">Sub #13</a> |
21 | <a href="#">Sub #14</a> |
24 | <a href="#">Parent link #2</a> |
25 | <a href="#">Sub #21</a> |
26 | <a href="#">Sub #22</a> |
27 | <a href="#">Sub #23</a> |
28 | <a href="#">Sub #24</a> |
31 | <a href="#">Parent link #3</a> |
32 | <a href="#">Sub #31</a> |
33 | <a href="#">Sub #32</a> |
34 | <a href="#">Sub #33</a> |
35 | <a href="#">Sub #34</a> |
38 | <a href="#">Parent link #4</a> |
39 | <a href="#">Sub #41</a> |
40 | <a href="#">Sub #42</a> |
41 | <a href="#">Sub #43</a> |
42 | <a href="#">Sub #44</a> |
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 test page. We will not publish these styles in this article, but if you wish – you can find these styles in our package.
002 | border: 1px solid #454545; |
008 | -moz-border-radius: 9px; |
009 | -ms-border-radius: 9px; |
010 | -webkit-border-radius: 9px; |
011 | -o-border-radius: 9px; |
013 | background: -moz-linear-gradient(#f1f7ff, #d9e1ec); |
014 | background: -ms-linear-gradient(#f1f7ff, #d9e1ec); |
015 | background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #f1f7ff), color-stop(100%, #d9e1ec)); |
016 | background: -webkit-linear-gradient(#f1f7ff, #d9e1ec); |
017 | background: -o-linear-gradient(#f1f7ff, #d9e1ec); |
018 | filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#f1f7ff', endColorstr='#d9e1ec'); |
019 | -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr='#f1f7ff', endColorstr='#d9e1ec')"; |
020 | background: linear-gradient(#f1f7ff, #d9e1ec); |
022 | @-moz-keyframes custom_effect { |
024 | background:rgba(255, 255, 255, 0.0); |
028 | background:rgba(255, 255, 255, 0.0); |
032 | background:rgba(255, 255, 255, 1.0); |
035 | background:rgba(190, 220, 255, 0.8); |
039 | @-webkit-keyframes custom_effect { |
041 | background:rgba(255, 255, 255, 0.0); |
045 | background:rgba(255, 255, 255, 0.0); |
049 | background:rgba(255, 255, 255, 1.0); |
052 | background:rgba(190, 220, 255, 0.8); |
057 | -moz-border-radius: 9px; |
058 | -ms-border-radius: 9px; |
059 | -webkit-border-radius: 9px; |
060 | -o-border-radius: 9px; |
062 | background-color:transparent; |
063 | border: 1px solid #454545; |
071 | -moz-animation-name: custom_effect; |
072 | -moz-animation-duration: 0.4s; |
073 | -moz-animation-timing-function: ease; |
074 | -moz-animation-iteration-count: 1; |
075 | -moz-animation-direction: normal; |
076 | -moz-animation-delay: 0; |
077 | -moz-animation-play-state: running; |
078 | -moz-animation-fill-mode: forwards; |
079 | -webkit-animation-name: custom_effect; |
080 | -webkit-animation-duration: 0.4s; |
081 | -webkit-animation-timing-function: ease; |
082 | -webkit-animation-iteration-count: 1; |
083 | -webkit-animation-direction: normal; |
084 | -webkit-animation-delay: 0; |
085 | -webkit-animation-play-state: running; |
086 | -webkit-animation-fill-mode: forwards; |
087 | background:rgba(190, 220, 255, 0.8); |
102 | text-decoration: none; |
103 | text-shadow: 0 1px 1px #FFFFFF; |
104 | vertical-align: middle; |
105 | -moz-transition: all 0.1s 0.4s; |
106 | -ms-transition: all 0.1s 0.4s; |
107 | -o-transition: all 0.1s 0.4s; |
108 | -webkit-transition: all 0.1s 0.4s; |
109 | transition: all 0.1s 0.4s; |
112 | text-decoration: underline; |
114 | ul#nav li a:first-child { |
120 | ul#nav li:hover a:first-child { |
Conclusion
Hope you enjoyed with new menu, don’t forget to tell thanks and leave a comment 🙂 Good luck!