Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap uncollapsed panel by default

I have a collapsable panel but I want it to be uncollapsed by default.

<div class="panel panel-default">     <div class="panel-heading">         <h4 class="panel-title">             <a data-toggle="collapse" href="#collapse1">                 <span class="glyphicon glyphicon-collapse-down"> </span>1st Round</a>         </h4>     </div>     <div id="collapse1" class="panel-collapse collapse">         <div class="panel-body">First round details</div>      </div> </div> 

If I remove collapse from

<div id="collapse1" class="panel-collapse collapse"> 

It works, but the first time clicked to uncollapse doesn't work.

like image 789
EddyG Avatar asked Mar 09 '17 06:03

EddyG


People also ask

How do I make Bootstrap collapse open by default?

If you've set the collapsible element to be open by default using the show class, set aria-expanded="true" on the control instead.

How do I collapse open by default?

Just add data-toggle="collapse" and a data-target to element to automatically assign control of a collapsible element. The data-target attribute accepts a CSS selector to apply the collapse to. Be sure to add the class collapse to the collapsible element. If you'd like it to default open, add the additional class in.

How do you collapse an accordion 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 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

In Bootstrap 3.x, add a class "in" to your collapsable div

<div id="collapse1" class="panel-collapse collapse in"> 

It will keep your div open by default.

Update:

With Bootstrap 4.0, You need to add show class in place of in.

like image 94
Kamlesh Arya Avatar answered Oct 07 '22 12:10

Kamlesh Arya


With Boostrap 4, simply add the class show to show the collapsed content on page load:

<div class="collapse show">...</div> 

As per Bootstrap 4 documention:

  • .collapse hides content
  • .collapse.show shows content
like image 35
maelga Avatar answered Oct 07 '22 13:10

maelga