[HTML] How to make it close when you click on the accordion menu?

Asked 2 years ago, Updated 2 years ago, 23 views

When you click on the first menu and click on the next menu, Both the first menu and the next menu open.

When there's an accordion menu [1][2][3]... If you click on the first menu, it opens If you click the next menu, the first menu closes and the next menu opens Please help me with how to add the contents from the source below.


<style>
.accordion {
    font-family:Arial, Helvetica, sans-serif; 
    margin:0 auto;
    font-size:14px;
    border:1px solid #542437;
    border-radius:10px;
    width:600px;
    padding:10px;
    background:#fff;
}
.accordion ul {
    list-style:none;
    margin:0;
    padding:0;    
}
.accordion li {
    margin:0;
    padding:0;
}
.accordion [type=radio], .accordion [type=checkbox] {
    display:none;
}
.accordion label {
    display:block;
    font-size:16px;
    line-height:16px;
    background:#D95B43;
    border:1px solid #542437;
    color:#542437;
    text-shadow:1px 1px 1px rgba(255,255,255,0.3);
    font-weight:700;
    cursor:pointer;
    text-transform:uppercase;
    -webkit-transition: all .2s ease-out;
    -moz-transition: all .2s ease-out;
}
.accordion ul li label:hover, .accordion [type=radio]:checked ~ label, .accordion [type=checkbox]:checked ~ label {
    background:#C02942;
    color:#FFF;
    text-shadow:1px 1px 1px rgba(0,0,0,0.5)
}
.accordion .content {
    padding:0 10px;
    overflow:hidden;
    border:1px solid #fff; /* Make the border match the background so it fades in nicely */
    -webkit-transition: all .5s ease-out;
    -moz-transition: all .5s ease-out;
}
.accordion p {
    color:#333;
    margin:0 0 10px;
}
.accordion h3 {
    color:#542437;
    padding:0;
    margin:10px 0;
}


/* /* Vertical */
.vertical ul li {
    overflow:hidden;
    margin:0 0 1px;
}
.vertical ul li label {
    padding:10px;
}
.vertical [type=radio]:checked ~ label, .vertical [type=checkbox]:checked ~ label {
    border-bottom:0;
}
.vertical ul li label:hover {
    border:1px solid #542437; /* We don't want the border to disappear on hover */
}
.vertical ul li .content {
    height:0px;
    border-top:0;
}
.vertical [type=radio]:checked ~ label ~ .content, .vertical [type=checkbox]:checked ~ label ~ .content {
    height:300px;
    border:1px solid #542437;
}
</style>
<div class="accordion vertical">
    <ul>
        <li>
            <input type="checkbox" id="checkbox-1" name="checkbox-accordion" />
            <label for="checkbox-1">Title&nbsp;One</label>
            <div class="content">
                <h3>A</h3>
                <p>AA</p>
            </div>
        </li>
        <li>
            <input type="checkbox" id="checkbox-2" name="checkbox-accordion" />
            <label for="checkbox-2">Title&nbsp;Two</label>
            <div class="content">
                <h3>B</h3>
                <p>BB</p>
            </div>
        </li>
        <li>
            <input type="checkbox" id="checkbox-3" name="checkbox-accordion" />
            <label for="checkbox-3">Title&nbsp;Three</label>
            <div class="content">
                <h3>C</h3>
                <p>CC</p>
            </div>
        </li>
    </ul>
</div>

html java

2022-09-21 23:22

1 Answers

It's easy to use Bootstrap & JavaScript. Please refer to this place. http://getbootstrap.com/docs/4.0/components/collapse/


2022-09-21 23:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.