I am currently working on creating Bootstrap accordions to display supplementary information. However, I have encountered an issue where clicking on one accordion opens all of them simultaneously. Is there a way in HTML, CSS, or JS to prevent this from happening? The extensive CSS code is mainly for aesthetic purposes like hiding highlights and glow effects, with the primary focus being on maintaining the basic accordion structure. Thank you for your help!
UPDATE: I was able to resolve the initial problem, but now when I refresh the page, all accordions are collapsed as desired. However, the arrows appear blue and pointing upwards, indicating they are open. It's only after toggling them twice that they correctly display the collapsed arrow.
Below is the code snippet:
<div class="col-12 offset-4 my-5" id="dropdowns">
<h4 id="data" class="ph">Test accordions</h2>
<div class="accordion">
<div class="accordion-item">
<button style="font-weight: bold; background-color: #f5f5f5;"class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
Test
</button>
<div id="collapseOne"class="accordion-collapse collapse show" aria-labelledby="headingOne" data-bs-parent="#accordionExample">
<div class="accordion-body" style="background-color: #f5f5f5;">
Placeholder text
</div>
</div>
</div>
<div class="accordion-item">
<button style="font-weight: bold; background-color: #f5f5f5;"class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
Test
</button>
<div id="collapseOne"class="accordion-collapse collapse show" aria-labelledby="headingOne" data-bs-parent="#accordionExample">
<div class="accordion-body" style="background-color: #f5f5f5;">
Placeholder text
</div>
</div>
</div>
<div class="accordion-item">
<button style="font-weight: bold; background-color: #f5f5f5;"class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
Test
</button>
<div id="collapseOne"class="accordion-collapse collapse show" aria-labelledby="headingOne" data-bs-parent="#accordionExample">
<div class="accordion-body" style="background-color: #f5f5f5;">
Placeholder text
</div>
</div>
</div>
<div class="accordion-item">
<button style="font-weight: bold; background-color: #f5f5f5;"class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
Test
</button>
<div id="collapseOne"class="accordion-collapse collapse show" aria-labelledby="headingOne" data-bs-parent="#accordionExample">
<div class="accordion-body" style="background-color: #f5f5f5;">
Placeholder text
</div>
</div>
</div>
<div class="accordion-item">
<button style="font-weight: bold; background-color: #f5f5f5;"class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
Test
</button>
<div id="collapseOne"class="accordion-collapse collapse show" aria-labelledby="headingOne" data-bs-parent="#accordionExample">
<div class="accordion-body" style="background-color: #f5f5f5;">
Placeholder text
</div>
</div>
</div>
</div>
</div>
.ph {
font-weight: bold;
}
.accordion-button:focus {
font-weight: bold;
box-shadow: none;
border-color: black;
}
.accordion-button:not(.collapsed) {
color: black;
background-color: #f5f5f5;
}
.accordion-button:link, .accordion-button:visited, .accordion-button:hover, .accordion-button:active {
background-color: #f5f5f5;
color: black;
text-decoration: none;
border: hidden;
border-color: #f5f5f5;
box-shadow: 0px;
}
/* .accordion-button:focus {
z-index: 3;
border-color: #f5f5f5;
outline: 0;
box-shadow: 0 0 0 .25rem #f5f5f5;
background-color: #f5f5f5;
} */
.accordion-item {
border-top: hidden;
border-left: hidden;
border-right: hidden;
border-bottom-color: #d4d4d4;
border-bottom-style: solid;
border-bottom-width: 2px;
/* width: 100%; */
/* padding-left: 0px;
padding-right: 0px; */
}
.accordion-button {
/* position: absolute;
left: 0px; */
padding-left: 0px;
}