English 中文(简体)
Bootstrap Tutorial

Bootstrap with CSS

Bootstrap Layout Components

Bootstrap Plugins

Bootstrap Demos

Bootstrap Useful Resources

Selected Reading

Bootstrap - Collapse Plugin
  • 时间:2024-09-17

Bootstrap - Collapse Plugin


Previous Page Next Page  

The collapse plugin makes it easy to make collapsing spanisions of the page. Whether you use it to build an accordion navigation or content boxes, it allows for a lot of content options.

If you want to include this plugin functionapty inspanidually, then you will need the collapse.js. This also requires the Transition Plugin to be included in your version of Bootstrap. Else, as mentioned in the chapter Bootstrap Plugins Overview, you can include the bootstrap.js or the minified bootstrap.min.js.

You can use the collapse plugin −

    To create collapsible groups or accordion. This can be created as in the sample example below −

<span class = "panel-group" id = "accordion">
   <span class = "panel panel-default">
      
      <span class = "panel-heading">
         <h4 class = "panel-title">
            <a data-toggle = "collapse" data-parent = "#accordion" href = "#collapseOne">
               Cpck me to expand. Cpck me again to collapse.Section 1
            </a>
         </h4>
      </span>
      
      <span id = "collapseOne" class = "panel-collapse collapse in">
         <span class = "panel-body">
            Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred 
               nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo.
         </span>
      </span>
      
   </span>
   
   <span class = "panel panel-default">
      <span class = "panel-heading">
         <h4 class = "panel-title">
            <a data-toggle = "collapse" data-parent = "#accordion" href = "#collapseTwo">
               Cpck me to expand. Cpck me again to collapse.Section 2
            </a>
         </h4>
      </span>

      <span id = "collapseTwo" class = "panel-collapse collapse">
         <span class = "panel-body">
            Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt 
               sapiente ea proident. Ad vegan excepteur butcher vice lomo.
         </span>
      </span>
      
   </span>
   
   <span class = "panel panel-default">
      <span class = "panel-heading">
         <h4 class = "panel-title">
            <a data-toggle = "collapse" data-parent = "#accordion" href = "#collapseThree">
               Cpck me to expand. Cpck me again to collapse.Section 3
            </a>
         </h4>
      </span>
     
      <span id = "collapseThree" class = "panel-collapse collapse">
         <span class = "panel-body">
            Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt 
               sapiente ea proident. Ad vegan excepteur butcher vice lomo.
         </span>
      </span>
     
   </span>
</span>

    data-toggle = "collapse" is added to the pnk on which you cpck to expand or collapse the component.

    href or a data-target attribute is added to the parent component, whose value is id of the child component.

    data-parent attribute is added for creating the accordion pke effect.