I have a accordion.In hover
appear a border bottom with small width
.
How to expand this border bottom smoothly on click
?
var acc = document.getElementsByClassName("accordion");
var i;
let li = document.getElementsByTagName("li");
for (i = 0; i < acc.length; i++) {
acc[i].addEventListener("click", function () {
this.classList.toggle("active");
var panel = this.nextElementSibling;
if (panel.style.maxHeight) {
panel.style.maxHeight = null;
} else {
panel.style.maxHeight = panel.scrollHeight + "px";
}
});
}
.accordion {
font-size: 27px;
background-color: $default-white;
color: #444;
cursor: pointer;
padding: 18px;
width: 100%;
border: none;
text-align: center;
outline: none;
transition: 0.4s;
}
.active {
border-bottom: 1px solid $default-black;
}
.panel {
padding: 0 18px; // background-color: white;
max-height: 0;
overflow: hidden;
transition: max-height 0.2s ease-out;
}
a {
text-decoration: none;
color: $default-black;
text-align: center;
font-size: 18px;
font-family: 'fira_sansregular';
color: grey;
}
li:hover:before {
content: "";
position: absolute;
left: 40%;
height: 1px;
margin-top: 75px;
text-align: center;
width: 20%;
border-bottom: 1px solid #000;
}
ul {
list-style-type:none;
}
<ul class='nav'>
<li>
<button class="accordion">BLA BLAS</button>
<div class="panel">
<a href='#'>First bla</a>
<a href='#'>second bla</a>
<a href='#'>third bla</a>
<a href='#'>fourth bla</a>
</div>
</li>
<li>
<button class="accordion">FILOSOPHY OF BLA</button>
<div class="panel">
<a href='#'>Page 2</a>
</div>
</li>
<li>
<button class="accordion">BLA BLA</button>
<div class="panel">
<a href='#'>Page 3</a>
</div>
</li>
<li>
<button class="accordion">SOME BLA BLA</button>
<div class="panel">
<a href='#'>Page 4</a>
</div>
</li>
<li>
<button class="accordion">BLA BLA</button>
<div class="panel">
<a href='#'>Page 5</a>
</div>
</li>
</ul>