Bootstrap collapse

1

I'm creating a list using collapse in an interaction of loop , but they're all starting open, I'd like only the first item of my collapse to be open.

If you double click on one of the items, it closes all the others, leaving only what was clicked.

My view

<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
    @for (int i = 0; i < 10; i++)
    {
        <div class="panel panel-default">
            <div class="panel-heading" role="tab" id="heading_@i">
                <h4 class="panel-title">
                    <a data-toggle="collapse" data-parent="#accordion" href="#collapse_@i" aria-expanded="true" aria-controls="collapse_@i"
                       @{ if (i == 0) { <text> collapse</text>} else { <text></text>}}>
                        Collapsible Group Item #@i
                    </a>
                </h4>
            </div>
            <div id="collapse_@i" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="heading_@i">
                <div class="panel-body">
                    Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
                </div>
            </div>
        </div>
    }
</div>

Edited as suggested by Luis.

    
asked by anonymous 29.01.2015 / 13:25

2 answers

1

The solution is to change the div:

<div id="collapse_@i" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="heading_@i">

for

<div id="collapse_@i" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading_@i">

remove the style in

The style in causes the element where it is used to be visible, as can be seen in its definition that is found inside the file bootstrap.css

.collapse.in {
  display: block;
  visibility: visible;
}
    
29.01.2015 / 13:46
-1

I'm not sure where you set the element to collapse, but put a (i == 0) ? 'collapse' : ''; . It should not be the best solution, but it solves your problem.

    
29.01.2015 / 13:30