Web--Templates.org

Bootstrap Collapse Example

Overview

While you wihtout a doubt know, Bootstrap by default makes your site responsive, applying its components as a reference for placing, size, and so on.

Realising this, when we are to design a menu working with Bootstrap for front-end, we will have to follow a number of the standards and standards specified by Bootstrap to make it promptly building the components of the webpage to keep responsive correctly.

Some of the most useful options of using this particular framework is the setting up of menus demonstrated as needed, according to the activities of the users .

{ A great treatment to get making use of menus on tiny screens is to connect the options in a kind of dropdown that only starts when ever it is triggered. That is , set up a switch to trigger the menu as needed. It is certainly quite simple to execute this having Bootstrap, the features is all at the ready.

Bootstrap Collapse Responsive plugin permits you to button material on your webpages together with a couple of classes with the help of certain useful JavaScript. ( additional info)

Tips on how to work with the Bootstrap Collapse Group:

To generate the Bootstrap Collapse Content in to tiny screens, just simply put in 2 classes in the

<ul>
:
collapse
and
navbar-collapse

<Ul class = "nav navbar-nav collapse navbar-collapse">

Having this, you have the ability to make the menu be lost upon the smaller sized displays.

Within the

navbar-header
, just below
<a>
, produce an activation tab. The button is just the text message "menu" though it provides the
navbar-toggle
class. Besides, two other specifications set up their function by having the collapse, just as can be seen below:

<Button class = "navbar-toggle" type = "button"
    Data-target = ". Navbar-collapse" data-toggle = "collapse">
  menu
</ Button>

Every detail inside this feature are going to be rendered inside of the framework of the menu. Via cutting down the computer display, it compacts the inner components and cover, being visible only with clicking the

<button class = "navbar-toggle">
button to enlarge the menu.

In this way the menu will certainly come into view although will certainly not do the job when clicked. It's by reason of this performance in Bootstrap is implemented with JavaScript. The really good information is that we do not have to produce a JS code line anyway, but also for every thing to perform we have to add in Bootstrap JavaScript.

At the end of the webpage, just before shutting

</body>
, call the Bootstrap and jQuery file:

<Script src = "js / jquery.js"> </ script>
<Script src = "js / bootstrap.js"> </ script>

For examples

Click the tabs listed here to demonstrate and conceal another feature with class modifications:

-

.collapse
hides information

-

.collapsing
is used while transitions

-

.collapse.show
displays content

You can use a backlink with the

href
attribute, or a button together with the
data-target
attribute. In each of the cases, the
data-toggle="collapse"
is needed.

 Representations

 As an examples
<p>
  <a class="btn btn-primary" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
    Link with href
  </a>
  <button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
    Button with data-target
  </button>
</p>
<div class="collapse" id="collapseExample">
  <div class="card card-block">
    Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident.
  </div>
</div>

Accordion example

Enhance the default collapse behavior to set up an accordion.

Accordion  an example
<div id="accordion" role="tablist" aria-multiselectable="true">
  <div class="card">
    <div class="card-header" role="tab" id="headingOne">
      <h5 class="mb-0">
        <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
          Collapsible Group Item #1
        </a>
      </h5>
    </div>

    <div id="collapseOne" class="collapse show" role="tabpanel" aria-labelledby="headingOne">
      <div class="card-block">
        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 class="card">
    <div class="card-header" role="tab" id="headingTwo">
      <h5 class="mb-0">
        <a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
          Collapsible Group Item #2
        </a>
      </h5>
    </div>
    <div id="collapseTwo" class="collapse" role="tabpanel" aria-labelledby="headingTwo">
      <div class="card-block">
        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 class="card">
    <div class="card-header" role="tab" id="headingThree">
      <h5 class="mb-0">
        <a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
          Collapsible Group Item #3
        </a>
      </h5>
    </div>
    <div id="collapseThree" class="collapse" role="tabpanel" aria-labelledby="headingThree">
      <div class="card-block">
        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>

Handiness

Be sure to provide

aria-expanded
to the control component. This particular attribute clearly specifies the current state of the collapsible element to screen readers as well as related assistive systems . If the collapsible feature is closed up by default, it should have a value of
aria-expanded="false"
In the event that you have certainly established the collapsible element to become exposed by default using the
show
class, put
aria-expanded="true"
on the control as a substitute. The plugin will promptly toggle this attribute built upon regardless if the collapsible feature has been launched or shut down. ( learn more here)

And additionally, in the event that your control component is targeting a one collapsible component-- such as the

data-target
attribute is pointing to an
id
selector-- you can bring in an added

aria-controls
attribute to the control feature, consisting of the
id
of the collapsible component . Modern-day screen readers and the same assistive technologies utilize this attribute in order to provide users with more quick ways to find your way straight to the collapsible feature itself.

Handling

The collapse plugin applies a few classes to resolve the hefty lifting:

-

.collapse
disguise material

-

.collapse.show
reveals web content

-

.collapsing
is provided when the transition sets up , and extracted as soon as it ends up

All of these classes may be found in

_transitions.scss

Via information attributes

Just include

data-toggle="collapse"
and a
data-target
to the element to instantly assign control of a collapsible feature. The
data-target
attribute takes a CSS selector to put the collapse to. Make sure to add the class
collapse
to the collapsible component. In the event that you 'd desire it to default open, include the additional class
show

To put in accordion-like group management to a collapsible control, provide the data attribute

data-parent="#selector"
Check out the demo to discover this at work.

By means of JavaScript

Make it possible manually by using:

$('.collapse').collapse()

Possibilities

Features can be pass on using data attributes or JavaScript. For data attributes, attach the feature name to

data-
, as in
data-parent=""

Practices

.collapse(options)

Switches on your content as a collapsible element. Takes on an extra alternatives

object

$('#myCollapsible').collapse(
  toggle: false
)

.collapse('toggle')

Button a collapsible component to displayed or else concealed.

.collapse('show')

Displays a collapsible element.

.collapse('hide')

Covers a collapsible component.

Activities

Bootstrap's collapse class displays a few events for fixing into collapse functionality.

$('#myCollapsible').on('hidden.bs.collapse', function () 
  // do something…
)

Final thoughts

We apply Bootstrap JavaScript implicitly, for a practical and quick effects, with no excellent programming attempt we will definitely have a excellent result.

Though, it is not actually only handy for developing menus, yet in addition any other elements for displaying or covering up on-screen elements, according to the decisions and interests of users.

In general these capabilities are at the same time useful for covering or presenting large quantities of data, empowering even more dynamism to the internet site and also keeping the layout cleaner.

Examine a couple of youtube video information about Bootstrap collapse

Connected topics:

Bootstrap collapse official documents

Bootstrap collapse official documentation

Bootstrap collapse tutorial

Bootstrap collapse   short training

Bootstrap collapse trouble

Bootstrap collapse issue