I am using the bootstrap template and I would like to change the way the accordion works by default.
How can I get the toggle to be closed when page is first seen (u
need to delete show from class:
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
It have to be
<div id="collapseOne" class="collapse" aria-labelledby="headingOne" data-parent="#accordion">
I just added class hide to the div before "card-body" and it hidden by default.
<div id="collapseOne" class="collapse hide" aria-labelledby="headingOne" data-parent="#accordion">
If removing the in
class doesn't work for you, such was my case, you can force the collapsed initial state using the CSS display property:
...
<div id="collapseOne" class="accordion-body collapse" style="display: none;">
...
When you expand or collapse accordion it just adds/removes a class "in" and sets the height:auto
or 0
to the accordion div.
Demo
So in your accordion when you define it just remove "in" class from the div as below. Whenever you expand an accorion it just adds the "in" class to make it visible.
If you render the page with "in" bootstrap looks for the class and it will make the div's height:auto, if it not present it will be at zero height.
<div id="collapseOne" class="accordion-body collapse">
Just add class "show" to the collapsing element's class, bootstrap will use js dynamically to remove it to collapse and show
There is a class in accordian which just adjust height from height:auto or 0 to the accordian div.
if you remove 'in' class and when you click on it, bootstrap adds 'in' class again and now content will be visible
<div id="collapseOne" class="accordion-body collapse">
....
</div>