CSS3 multilevel menu with transition and animation

Tutorials

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:

Live Demo
download in 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

01 <!DOCTYPE html>
02 <html lang="en" >
03     <head>
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">
08     </head>
09     <body>
10         <header>
11             <h2>CSS3 multilevel menu with transition and animation</h2>
12             <a href="https://www.script-tutorials.com/css3-multilevel-menu-with-transition-and-animation/" class="stuts">Back to original tutorial on <span>Script Tutorials</span></a>
13         </header>
14         <div class="container">
15             <ul id="nav">
16                 <li>
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>
22                 </li>
23                 <li>
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>
29                 </li>
30                 <li>
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>
36                 </li>
37                 <li>
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>
43                 </li>
44             </ul>
45         </div>
46     </body>
47 </html>

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.

css/menu.css

001 ul#nav {
002     border1px solid #454545;
003     displayblock;
004     height400px;
005     margin0;
006     padding15px;
007     width160px;
008     -moz-border-radius: 9px;
009     -ms-border-radius: 9px;
010     -webkit-border-radius: 9px;
011     -o-border-radius: 9px;
012     border-radius: 9px;
013     background: -moz-linear-gradient(#f1f7ff#d9e1ec);
014     background: -ms-linear-gradient(#f1f7ff#d9e1ec);
015     background: -webkit-gradient(linear, left topleft 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);
021 }
022 @-moz-keyframes custom_effect {
023     0% {
024         background:rgba(2552552550.0);
025         height60px;
026     }
027     33% {
028         background:rgba(2552552550.0);
029         height160px;
030     }
031     66% {
032         background:rgba(2552552551.0);
033     }
034     100% {
035         background:rgba(1902202550.8);
036         height135px;
037     }
038 }
039 @-webkit-keyframes custom_effect {
040     0% {
041         background:rgba(2552552550.0);
042         height60px;
043     }
044     33% {
045         background:rgba(2552552550.0);
046         height160px;
047     }
048     66% {
049         background:rgba(2552552551.0);
050     }
051     100% {
052         background:rgba(1902202550.8);
053         height135px;
054     }
055 }
056 ul#nav li {
057     -moz-border-radius: 9px;
058     -ms-border-radius: 9px;
059     -webkit-border-radius: 9px;
060     -o-border-radius: 9px;
061     border-radius: 9px;
062     background-color:transparent;
063     border1px solid #454545;
064     displayblock;
065     height60px;
066     line-height60px;
067     margin-bottom15px;
068     overflowhidden;
069 }
070 ul#nav li:hover {
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-directionnormal;
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-directionnormal;
084     -webkit-animation-delay: 0;
085     -webkit-animation-play-state: running;
086     -webkit-animation-fill-mode: forwards;
087     background:rgba(1902202550.8);
088     height135px;
089 }
090 ul#nav a {
091     border-stylenone;
092     border-width0;
093     color#181818;
094     cursorpointer;
095     floatleft;
096     font-size13px;
097     font-weightbold;
098     line-height30px;
099     margin-top100px;
100     padding-left18px;
101     text-alignleft;
102     text-decorationnone;
103     text-shadow0 1px 1px #FFFFFF;
104     vertical-alignmiddle;
105     -moz-transition: all 0.10.4s;
106     -ms-transition: all 0.10.4s;
107     -o-transition: all 0.10.4s;
108     -webkit-transition: all 0.10.4s;
109     transition: all 0.10.4s;
110 }
111 ul#nav a:hover {
112     text-decorationunderline;
113 }
114 ul#nav li a:first-child {
115     displayblock;
116     floatnone;
117     line-height60px;
118     margin-top0;
119 }
120 ul#nav li:hover a:first-child {
121     line-height60px;
122 }
123 ul#nav li:hover a {
124     margin-top0;
125 }

Live Demo
download in package

Conclusion

Hope you enjoyed with new menu, don’t forget to tell thanks and leave a comment 🙂 Good luck!

Rate article