Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap Accordion - start all closed

So I have a bootstrap style accordion on my page - but on start, the first panel is open. How can i make it so that when you load the page, they are all closed?

Any help would be really appreciated! Thanks so much!

<div class="panel-group" id="accordion">     <div class="panel panel-default">         <div class="panel-heading">             <h4 class="panel-title">                 <a class="accordion-toggle text-normalize" data-toggle="collapse" data-parent="#accordion" href="#panel1"><i class="fa fa-minus text-primary"></i> Overview</a>             </h4>         </div>         <div id="panel1" class="panel-collapse collapse in">             <div class="panel-body">Contents panel 1</div>         </div>     </div>     <div class="panel panel-default">         <div class="panel-heading">             <h4 class="panel-title">                 <a class="accordion-toggle text-normalize" data-toggle="collapse" data-parent="#accordion" href="#panel2"><i class="fa fa-plus text-primary"></i> Utilities</a>             </h4>         </div>         <div id="panel2" class="panel-collapse collapse">             <div class="panel-body">Contents panel 2</div>         </div>     </div>     <div class="panel panel-default">         <div class="panel-heading">             <h4 class="panel-title">                 <a class="accordion-toggle text-normalize" data-toggle="collapse" data-parent="#accordion" href="#panel3"><i class="fa fa-plus text-primary"></i> Organization</a>             </h4>         </div>         <div id="panel3" class="panel-collapse collapse">             <div class="panel-body">Contents panel 3</div>         </div>     </div>     <div class="panel panel-default">         <div class="panel-heading">             <h4 class="panel-title">                 <a class="accordion-toggle text-normalize" data-toggle="collapse" data-parent="#accordion" href="#panel4"><i class="fa fa-plus text-primary"></i> Integrations</a>             </h4>         </div>         <div id="panel4" class="panel-collapse collapse">             <div class="panel-body">Contents panel 3</div>         </div>     </div>     <div class="panel panel-default">         <div class="panel-heading">             <h4 class="panel-title">                 <a class="accordion-toggle text-normalize" data-toggle="collapse" data-parent="#accordion" href="#panel5"><i class="fa fa-plus text-primary"></i> Essentials</a>             </h4>         </div>         <div id="panel5" class="panel-collapse collapse">             <div class="panel-body">Contents panel 3</div>         </div>     </div>     <div class="panel panel-default">         <div class="panel-heading">             <h4 class="panel-title">                 <a class="accordion-toggle text-normalize" data-toggle="collapse" data-parent="#accordion" href="#panel6"><i class="fa fa-plus text-primary"></i> Sales</a>             </h4>         </div>         <div id="panel6" class="panel-collapse collapse">             <div class="panel-body">Contents panel 3</div>         </div>     </div>     <div class="panel panel-default">         <div class="panel-heading">             <h4 class="panel-title">                 <a class="accordion-toggle text-normalize" data-toggle="collapse" data-parent="#accordion" href="#panel7"><i class="fa fa-plus text-primary"></i> Support</a>             </h4>         </div>         <div id="panel7" class="panel-collapse collapse">             <div class="panel-body">Contents panel 3</div>         </div>     </div>     <div class="panel panel-default">         <div class="panel-heading">             <h4 class="panel-title">                 <a class="accordion-toggle text-normalize" data-toggle="collapse" data-parent="#accordion" href="#panel8"><i class="fa fa-plus text-primary"></i> Projects</a>             </h4>         </div>         <div id="panel8" class="panel-collapse collapse">             <div class="panel-body">Contents panel 3</div>         </div>     </div> </div> 
like image 659
becca Avatar asked May 31 '16 13:05

becca


People also ask

How do I make accordion closed by default bootstrap?

Just add data-toggle="collapse" and a data-target to the element to automatically assign control of one or more collapsible elements. The data-target attribute accepts a CSS selector to apply the collapse to. Be sure to add the class collapse to the collapsible element.

How do I make my accordion closed by default?

To create an accordion that is collapsed by default, we need to set the 'active' property of the jQuery Accordion as false. Syntax: $("#demoAccordion"). accordion({ collapsible: true, active: false});

How do you close an accordion when another opens?

open accordian > at right side go to accordian seting > scrol down to Expand/Collapse Accordion Option On Page Load > choose Hide/close All Accordion.. thanks.

How do you keep multiple collapses open in bootstrap 4?

Assuming that you're using Bootstrap 4, you can simply remove the data-parent attribute from the element with the collapse class. This subscribes the collapse to events on #accordionExample , which is the main accordion element, via the data-parent attribute.


2 Answers

Boostrap 3

Just remove .in from panel1.

<div id="panel1" class="panel-collapse collapse">    <div class="panel-body">Contents panel 1</div> </div> 

Bootstrap 4

See @Syed Sajid's answer

like image 185
Steven B. Avatar answered Sep 19 '22 19:09

Steven B.


Bootstrap 4 and 4+ remove class show from collapse show

<div class="collapse">     <div class="card-body"></div> </div> 
like image 37
Syed Sajid Avatar answered Sep 19 '22 19:09

Syed Sajid