0

I'm trying to transition effect for my menu's dropdown, but unlike the other cases, I can't manage to get it work. I've search lots of theards around here and over google as well. I found no solution.

Here's my code:

.dropdown2 {
    position: relative;
    display: inline-block;
}

.dropdown-content2 {
    display: none;
    position: absolute;
    background-color: #e1e1e1;
    color: #000;
    min-width: 150px;
    height: 220px;
    z-index: 999;
    font-size: 20px;
    margin-right: -10px;
    top: 34px;
    transition: height 2s;
}

.dropdown-content2 a {
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    border-bottom: 5px solid white;
}

.dropdown2:hover .dropdown-content2 {
    display: block;
}


.dropdown2:hover .dropbtn2 {
    background-color: #e1e1e1;
}

HTML:

                <div class="menu_option dropdown2"><a href="?go=articles">articles</a>
                    <div class="dropdown-content2">
                        <a href="?go=news">news</a>
                        <a href="?go=reviews">reviews</a>
                        <a href="?go=guides">guides</a>
                        <a href="?go=art">art</a>
                    </div>
                </div>

And it doesn't work.

Paulie_D
  • 107,962
  • 13
  • 142
  • 161
Ori R
  • 7
  • 6

2 Answers2

0

try like this.. in display none and block transition effect not working.. so now i changed opacity

HTML

   <div class="menu_option dropdown2"><a href="?go=כתבות">כל הכתבות</a>
                    <div class="dropdown-content2">
                        <a href="?go=news">news</a>
                        <a href="?go=reviews">reviews</a>
                        <a href="?go=guides">guides</a>
                        <a href="?go=art">art</a>
                    </div>
                </div>

css

.dropdown2 {
    position: relative;
    display: inline-block;
}

.dropdown-content2 {
   opacity:0;
   visibility:hidden;
    position: absolute;
    background-color: #e1e1e1;
    color: #000;
    min-width: 150px;
    height: 220px;
    z-index: 999;
    font-size: 20px;
    margin-right: -10px;
    top: 34px;
    -webkit-transition: all 0.5s ease;
-ms-transition: all 0.5s ease;
transition: all 0.5s ease
}

.dropdown-content2 a {
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    border-bottom: 5px solid white;
}

.dropdown2:hover .dropdown-content2 {
    opacity:1;
   visibility:visible;
    -webkit-transition: all 0.5s ease;
-ms-transition: all 0.5s ease;
transition: all 0.5s ease
}


.dropdown2:hover .dropbtn2 {
    background-color: #e1e1e1;
}
Ranjith v
  • 1,032
  • 5
  • 15
0

You can't transition from display: none to display: block.

Fortunately, in this case you don't need to. You only need to transition from height: 0 to height: 220px.

N.B. You also need to ensure that .dropdown-content2 has the style overflow: hidden to ensure that when the content of the parent element exceeds the height, it does not overflow the boundaries and reveal itself.

Working Example:

.dropdown2 {
    position: relative;
    display: inline-block;
}

.dropdown-content2 {
    position: absolute;
    background-color: #e1e1e1;
    color: #000;
    min-width: 150px;
    z-index: 999;
    font-size: 20px;
    margin-right: -10px;
    top: 34px;
    overflow: hidden;
}

.dropdown-content2 a {
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    border-bottom: 5px solid white;
}

.dropdown2 .dropdown-content2 {
    height: 0;
    transition: height 2s;
}

.dropdown2:hover .dropdown-content2 {
    height: 220px;
}


.dropdown2:hover .dropbtn2 {
    background-color: #e1e1e1;
}
<div class="menu_option dropdown2"><a href="?go=articles">articles</a>
<div class="dropdown-content2">
<a href="?go=news">news</a>
<a href="?go=reviews">reviews</a>
<a href="?go=guides">guides</a>
<a href="?go=art">art</a>
</div>
</div>
Rounin
  • 27,134
  • 9
  • 83
  • 108