#CSS:
.my-accordion .menu {
background-color: #d5d5d5;
color: #444;
cursor: pointer;
padding: 12px;
width: 100%;
text-align: left;
border: none;
outline: none;
margin-top: 4px;
border-radius: 8px;
font-size: inherit
}
.my-accordion .panel {
background-color: #FFFFFF;
color: #000000;
overflow: hidden
}
.my-accordion .open {
display: block
}
.my-accordion .close {
display: none
}
.my-accordion .active {
background-color: #1b90bb;
color: #fff
}
.my-accordion .arrow {
float: right;
display: block
}
.my-accordion .darrow {
display: none
}
.my-accordion .active .darrow {
display: block
}
.my-accordion .active .rarrow {
display: none
}
.my-accordion .panel a {
display: block;
background: #808080;
color: #FFFFFF;
padding: 5px;
margin: 3px;
width: 100%;
text-decoration: none
}
#HTML:
<div class="my-accordion">
<button class='menu'>Menu 1<span class='arrow rarrow'>+</span><span class='arrow darrow'>-</span></button>
<div class='panel close'>
<div><a href="">Link 1</a><a href="">Link 2</a><a href="">Link 3</a><a href="">Link 4</a></div>
</div>
<button class='menu'>Menu 2<span class='arrow rarrow'>+</span><span class='arrow darrow'>-</span></button>
<div class='panel close'>
<div><a href="">Link 1</a><a href="">Link 2</a><a href="">Link 3</a><a href="">Link 4</a></div>
</div>
<button class='menu'>Menu 3<span class='arrow rarrow'>+</span><span class='arrow darrow'>-</span></button>
<div class='panel close'>
<div style="padding:10px">Data will be added soon.</div>
</div>
</div>
#JAVASCRIPT:
! function() {
for (var l = document.querySelectorAll(".my-accordion .menu"), e = 0; e < l.length; e++) l[e].addEventListener("click", n);
function n() {
for (var e = document.querySelectorAll(".my-accordion .panel"), n = 0; n < e.length; n++) e[n].className = "panel close";
if (-1 == this.className.indexOf("active")) {
for (n = 0; n < l.length; n++) l[n].className = "menu";
this.className = "menu active", this.nextElementSibling.className = "panel open"
} else
for (n = 0; n < l.length; n++) l[n].className = "menu"
}
}();
它是带有 javascript 的 html 手风琴代码。要修改样式,请访问https://www.htmlcodegenerator-tools.com/2020/08/html-accordion-generator.html