I created a menu with a drop-down effect using CSS3 transitions. However, my issue is that the text is visible before the background appears, which goes against the intended design.
Here is a link to my JSFiddle.
HTML:
<nav>
<ul>
<li>Home</li>
<li>Parent Link
<ul>
<li>Child Link</li>
<li>Child Link</li>
<li>Parent Link
<ul>
<li>Child Link</li>
<li>Child Link</li>
<li>Child Link</li>
<li>Child Link</li>
<li>Child Link</li>
</ul>
</li>
</ul>
</li>
<li>About</li>
<li>Contact</li>
</ul>
</nav>
CSS:
nav {
position: fixed;
top: 0;
width: 100%;
height: 50px;
background: #30a0ff;
z-index: 2;
box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.3);
}
nav > ul {
position: relative;
margin: 0 auto;
padding: 0;
width: 100%;
list-style: none;
text-align: center;
}
nav > ul > li {
position: relative;
display: inline;
padding: 12px 20px;
line-height: 50px;
font-size: 22px;
color: #fff;
cursor: pointer;
}
nav > ul > li:last-child {
margin: 0 -20px 0 0;
}
nav ul li {
-webkit-transition: all 0.2s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
-ms-transition: all 0.2s ease-in-out;
-o-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
}
nav ul li:hover {
background-color: #0f71c4;
}
nav > ul > li > ul {
position: absolute;
top: 50px;
left: 0;
height: 0;
padding: 0;
list-style: none;
line-height: 20px;
font-size: 17px;
background-color: #30a0ff;
overflow: hidden;
}
nav > ul > li:hover > ul {
min-height: 110px;
overflow: visible;
}
nav > ul > li > ul > li:first-child {
padding: 15px 20px 5px 20px;
}
nav > ul > li > ul > li:last-child {
padding: 5px 20px 15px 20px;
}
nav > ul > li > ul > li {
position: relative;
padding: 5px 20px;
min-width: 150px;
text-align: left;
}
nav ul li ul {
box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.3);
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-ms-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
nav > ul > li > ul > li > ul {
position: absolute;
left: 190px;
top: 0;
padding: 0;
width: 0;
list-style: none;
font-size: 16px;
background-color: #30a0ff;
overflow: hidden;
}
nav > ul > li > ul > li:hover > ul {
min-width: 150px;
}
nav > ul > li > ul > li > ul > li {
position: relative;
padding: 5px 20px;
min-width: 150px;
}
nav > ul > li > ul > li > ul > li:first-child {
padding: 15px 20px 5px 20px;
}
nav > ul > li > ul > li > ul > li:last-child {
padding: 5px 20px 15px 20px;
}