This lightweight code snippet helps you to create Bootstrap collapsible panel with an up/down arrow icon. It can be used to collapse any contents like FAQs, explanation of a term, or as a general-purpose accordion.
How to Create Bootstrap Collapsible Panel with Up/Down Arrow Icon
1. First of all load the Boostrap framework and jQuery into your HTML document.
<!-- Bootstrap --> <link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css'> <script src='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js'></script> <!-- jQuery --> <script src='https://code.jquery.com/jquery-2.2.4.min.js'></script>
2. After that, create HTML strcuture for collapsible panels as follows:
<div class="wrapper center-block"> <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> <div class="panel panel-default"> <div class="panel-heading active" role="tab" id="headingOne"> <h4 class="panel-title"> <a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne"> Collapsible Group Item #1 </a> </h4> </div> <div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne"> <div class="panel-body"> Your contents... </div> </div> </div> <div class="panel panel-default"> <div class="panel-heading" role="tab" id="headingTwo"> <h4 class="panel-title"> <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo"> Collapsible Group Item #2 </a> </h4> </div> <div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo"> <div class="panel-body"> Your contents... </div> </div> </div> <div class="panel panel-default"> <div class="panel-heading" role="tab" id="headingThree"> <h4 class="panel-title"> <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseThree" aria-expanded="false" aria-controls="collapseThree"> Collapsible Group Item #3 </a> </h4> </div> <div id="collapseThree" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingThree"> <div class="panel-body"> Your contents... </div> </div> </div> </div> </div>
3. Now, design the collapsible panels with CSS.
.wrapper{ width:100%; } @media(max-width:992px){ .wrapper{ width:100%; } } .panel-heading { padding: 0; border:0; } .panel-title>a, .panel-title>a:active{ display:block; padding:15px; color:#555; font-size:16px; font-weight:bold; text-transform:uppercase; letter-spacing:1px; word-spacing:3px; text-decoration:none; } .panel-heading a:before { font-family: 'Glyphicons Halflings'; content: "\e114"; float: right; transition: all 0.5s; } .panel-heading.active a:before { -webkit-transform: rotate(180deg); -moz-transform: rotate(180deg); transform: rotate(180deg); }
4. Finally, add the following jQuery code snippet to toggle the up/down icon.
$('.panel-collapse').on('show.bs.collapse', function () { $(this).siblings('.panel-heading').addClass('active'); }); $('.panel-collapse').on('hide.bs.collapse', function () { $(this).siblings('.panel-heading').removeClass('active'); });
Similar Code Snippets:
I code and create web elements for amazing people around the world. I like work with new people. New people new Experiences.
I truly enjoy what I’m doing, which makes me more passionate about web development and coding. I am always ready to do challenging tasks whether it is about creating a custom CMS from scratch or customizing an existing system.
help full nice keep it up