Resize the browser window and see the effect.
<div class="showcontent">
<h3>Here color red is used for visualize purposes.</h3>
<div class="dropnav">
<a href="#" style="background-color: #04AA6A; color:white;">Home</a>
<a href="#">About</a>
<div class="dropdown">
<button onclick="myfun()">Dropdown ▼</button>
<div class="dropcontent">
<a href="#">link1</a>
<a href="#">link2</a>
<a href="#">link3</a>
</div>
</div>
</div>
</div>
function myfun(){
let content=document.querySelector(".dropcontent");
console.log(content.style.width);
if(content.style.width=="0%" ||content.style.width==""){
content.style.width="120px";
}
else{
content.style.width="0%";
}
}
*{
box-sizing: border-box;
}
.col-75 .showcontent{
overflow: hidden;
padding-bottom: 200px;
}
.dropnav{
background-color: #333;
display: flex;
align-items: center;
color: red;
border-radius: 5px;
}
.dropnav button{
padding: 14px 16px;
background-color: inherit;
border: none;
color: red;
font-size: 18px;
cursor: pointer;
overflow: hidden;
}
.dropnav button:hover{
background-color: black;
}
.dropnav a{
text-decoration: none;
padding: 14px 16px;
color: red;
font-size: 18px;
overflow: hidden;
white-space: nowrap;
}
.dropnav a:hover{
background-color: black;
}
.dropnav .dropcontent{
position: absolute;
display: flex;
z-index: 10;
flex-direction: column;
background-color:#444;
width: 0;
overflow: hidden;
transition: 1.4s;
transition-timing-function: ease-in-out;
}
@media screen and (max-width:300px) {
.dropnav{
flex-direction: column;
align-items: center;
justify-content: center;
}
.dropnav a,.dropnav button{
padding: 8px;
width: 100%;
text-align: center;
}
.dropnav a:hover,.dropnav button:hover{
width: 100%;
}
}