CSS dropdown menu transition
css, drop-down-menu, html
Solution
Your transition doesn't fire, because the `height` of your elements isn't changed during `:hover`, only `display` and `opacity`. To make your elements fade in - you need to change your transition property to `opacity` or `all`.
If you want to transition height - you need to set your element `height` to 0, and then change it on `:hover`.
Be aware though - height transitions work only for specified `height` value, and won't work for something like `height: auto;`. There is a workaround for it, as follows:
ul {
transition: all 0.5s;
max-height: 0;
}
ul:hover {
max-height: 200px; //or whatever could be your max-height value - don't overdo it, will be crappy transition.
}
Problem
I am trying to add dropdown transition for the menu I am working on, but it seems that I have no idea what I am doing wrong. The menu itself appears instantly, ignorning the transition effect. CSS code I use for transition: ``` -webkit-transition: height 0.3s ease-in; -moz-transition: height 0.3s ease-in; -o-transition: height 0.3s ease-in; -ms-transition: height 0.3s ease-in; transition: height 0.3s ease-in; opacity:0; ``` As far as I know I should add it to the `nav ul ul` CSS block, and adding `opacity:1` to `nav ul li:hover > ul` but it does not work. And here's whole code of the menu. HTML ``` <nav> <ul> <li><a href="http://www.www.com/">Menu 1</a></li> <li><a href="http://www.www.com/">Menu 2</a></li> <li><a>Dropdown Here</a> <ul> <li><a href="http://www.www.com/">Dropdown1</a></li> <li><a href="http://www.www.com/">Dropdown2</a></li> <li><a href="http://www.www.com/">Dropdown3</a></li> </ul> </li> <li><a href="http://www.www.com/">Menu 4</a></li> <li><a href="http://www.www.com/">Menu 5</a></li> </ul> </nav> ``` And the CSS I am using ``` nav ul { background: #efefef; background: linear-gradient(top, #efefef 0%, #bbbbbb 100%); background: -moz-linear-gradient(top, #efefef 0%, #bbbbbb 100%); background: -webkit-linear-gradient(top, #efefef 0%,#bbbbbb 100%); box-shadow: 0px 0px 9px rgba(0,0,0,0.15); padding: 0 25px; border-radius: 10px; list-style: none; position: relative; display: inline-table; float:right; z-index:9999; } nav ul ul { display: none; -webkit-transition: height 0.3s ease-in; -moz-transition: height 0.3s ease-in; -o-transition: height 0.3s ease-in; -ms-transition: height 0.3s ease-in; transition: height 0.3s ease-in; opacity:0; } nav ul li:hover > ul { display: block; opacity:1; } nav ul:after { content: ""; clear: both; display: block; } nav ul li { float: left; } nav ul li:hover { background: #4b545f; background: linear-gradient(top, #4f5964 0%, #5f6975 40%); background: -moz-linear-gradient(top, #4f5964 0%, #5f6975 40%); background: -webkit-linear-gradient(top, #4f5964 0%,#5f6975 40%); } nav ul li:hover a { color: #fff; } nav ul li a { display: block; padding: 30px 20px; color: #757575; text-decoration: none; } nav ul ul { background: #5f6975; border-radius: 0px; padding: 0; position: absolute; top: 100%; } nav ul ul li { float: none; border-top: 1px solid #6b727c; border-bottom: 1px solid #575f6a; position: relative; } nav ul ul li a { padding: 15px 40px; color: #fff; } nav ul ul li a:hover { background: #4b545f; } nav ul ul ul { position: absolute; left: 100%; top:0; } ```