I'm trying to add a transition to this dropdown:
HTML :
<div class="dropdown">
<button class="dropbtn">Select</button>
<div class="dropdown_content">
<a>1</a>
<a>2</a>
<a>3</a>
<a>4</a>
</div>
</div>
css :
.dropdown {
position: relative;
display: inline-block;
width: 150px;
}
.dropbtn {
background: #fff;
box-shadow: 0 0 10px rgba(0,0,0,0.5);
border-radius: 10px;
font-size: 20px;
color: #888;
border: none;
padding: 10px 10px;
width: 100%;
}
.dropdown_content {
position: absolute;
display: block;
height: 0px;
margin-top: -2px;
background: #fff;
width: 100%;
border-radius: 0px 0px 10px 10px;
box-shadow: 0 13px 15px rgba(0,0,0,0.5);
max-height: 150px;
overflow-y: scroll;
overflow-x: hidden;
transition: ease 0.5s;
}
.dropdown_content a {
display: block;
color: #555;
padding: 10px 0px;
transition: ease 0.2s;
cursor: pointer;
}
.dropdown_content a:hover {
background: #0092ED;
color: #fff;
}
.dropdown_content::-webkit-scrollbar {
display: none;
}
.dropdown:hover .dropdown_content {
height: auto;
}
.dropdown:hover .dropbtn {
border-radius: 10px 10px 0px 0px;
background: #0092ED;
color: #fff;
}
I know the browser can't calculate a transition from display: none;
to display: block;
but in this case I'm changing the height of the dropdown_content
and I don't understand why it's not working.
I also leave it in JS Fiddle to save the copy and paste.
I would appreciate any possible help
You have to use max-height instead of height and set a fixed height to max-height