HTML5Video-Tag.com

Bootstrap Collapse Example

Overview

As you wihtout a doubt identify, Bootstrap by default helps to make your site responsive, applying its features just as a reference for locating, sizing, and so forth.

Finding out this, if we are to make a menu applying Bootstrap for front-end, we will ought to comply with a number of the standards and standards established by Bootstrap making it automatically form the components of the page to leave responsive correctly.

Amongst the most fascinating options of using this framework is the making of menus exposed on demand, depending on the activities of the site visitors .

{ A great option to get using menus on small-sized display screens is to link the options in a type of dropdown which only sets up any time it is activated. That is , produce a switch to trigger the menu as needed. It is certainly very simple to do this by using Bootstrap, the capability is all at the ready.

Bootstrap Collapse Button plugin makes it possible for you to toggle web content within your pages with a couple of classes because of some valuable JavaScript. ( useful source)

How to use the Bootstrap Collapse Content:

To generate the Bootstrap Collapse Group into small-scale screens, just include 2 classes in the

<ul>
:
collapse
and
navbar-collapse

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

With this, you can certainly get the menu vanish upon the smaller sized display screens.

Within the

navbar-header
, exactly below
<a>
, make an activation button. The tab is simply just the text "menu" yet it possesses the
navbar-toggle
class. On top of that, a pair of some other parameters manage their function through the collapse, like can be discovered in this article:

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

All things inside of this component are going to be delivered within the framework of the menu. By cutting down the computer display screen, it packs the inside elements and cover, being visible only via clicking the

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

Through this the menu definitely will come into view yet will certainly not work when clicked. It is actually because this capability in Bootstrap is incorporated with JavaScript. The very good news is that we do not must write a JS code line at all, but for every thing to perform we should add Bootstrap JavaScript.

At the end of the page, 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 switches listed below to indicate and hide some other component through class changes:

-

.collapse
conceal content

-

.collapsing
is used while changes

-

.collapse.show
shows material

You are able to put into action a web link utilizing the

href
attribute, or a button having the
data-target
attribute. In both of these cases, the
data-toggle="collapse"
is requested.

 Representations

 Some 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 for example

Increase the default collapse behaviour to set up an accordion.

Accordion  representation
<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>

Availableness

Be sure to add in

aria-expanded
to the control part. This attribute explicitly defines the current status of the collapsible element to screen readers plus related assistive techniques . In the case that the collapsible feature is shut off by default, it needs to have a value of
aria-expanded="false"
If you have actually set the collapsible feature to be accessible through default utilizing the
show
class, put
aria-expanded="true"
on the control instead. The plugin will promptly toggle this attribute founded on regardless if the collapsible component has been opened or shut down. ( read more)

And additionally, in the event that your control component is aim for a one collapsible element-- i.e. the

data-target
attribute is leading to an
id
selector-- you may provide an extra

aria-controls
attribute to the control element, providing the
id
of the collapsible element . Present-day screen readers and similar assistive systems utilize this specific attribute in order to deliver users with supplementary faster ways to move right to the collapsible element itself.

Handling

The collapse plugin incorporates a number of classes to resolve the intense lifting:

-

.collapse
conceal web content

-

.collapse.show
shows material

-

.collapsing
is added in when the transition starts , and wiped out when it ends up

All these classes can easily be discovered in

_transitions.scss

Via data attributes

Simply provide

data-toggle="collapse"
plus a
data-target
to the element to quickly appoint control of a collapsible element. The
data-target
attribute accepts a CSS selector to apply the collapse to. Don't forget to incorporate the class
collapse
to the collapsible feature. In case you 'd wish it to default open, add the additional class
show

To bring in accordion-like group management to a collapsible control, include the data attribute

data-parent="#selector"
Refer to the demonstration to see this in action.

By JavaScript

Enable by hand through:

$('.collapse').collapse()

Options

Features can be passed through data attributes as well as JavaScript. For data attributes, append the option title to

data-
, as in
data-parent=""

Ways

.collapse(options)

Turns on your content as a collapsible feature. Receives an optional alternatives

object

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

.collapse('toggle')

Button a collapsible component to revealed or else covered up.

.collapse('show')

Presents a collapsible feature.

.collapse('hide')

Covers a collapsible feature.

Occasions

Bootstrap's collapse class displays a number of activities for hooking within collapse useful functionality.

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

Final thoughts

We use Bootstrap JavaScript implicitly, for a practical and fast result, without any perfect programming work we will have a excellent outcome.

However, it is not actually just handy for creating menus, yet additionally some other components for displaying or concealing on-screen parts, basing on the actions and requirements of users.

Generally these types of components are at the same time handy for covering or else revealing massive quantities of details, empowering additional dynamism to the website as well as keeping the layout cleaner.

Inspect several youtube video information regarding Bootstrap collapse

Connected topics:

Bootstrap collapse authoritative documentation

Bootstrap collapse  approved documentation

Bootstrap collapse information

Bootstrap collapse   information

Bootstrap collapse issue

Bootstrap collapse  complication