Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Collapse div/element on mobile screens only with bootstrap. Example pic

Is it possible to collapse a sidebar div - only on mobiles - using bootstrap? How would I go about doing something like the example in the image? So that on a mobiles the sidebar collapses and when clicked, expands. I don't understand how media queries would allow me to do this becuase of the jquery involved.

http://i46.tinypic.com/2mzxflu.jpg

Have seen some similar questions on here but nothing exactly like this. Could someone explain or at least point me in the right direction? Thanks in advance.

like image 283
user1261675 Avatar asked Jan 18 '13 13:01

user1261675


People also ask

How do I create a collapsible panel in Bootstrap?

Just add data-toggle="collapse" and a data-target to the element to automatically assign control of one or more collapsible elements. The data-target attribute accepts a CSS selector to apply the collapse to. Be sure to add the class collapse to the collapsible element.

How do you make a div collapse?

The .collapse class indicates a collapsible element (a <div> in our example); this is the content that will be shown or hidden with a click of a button. To control (show/hide) the collapsible content, add the data-toggle="collapse" attribute to an <a> or a <button> element.

How do you collapse an accordion by default?

To create an accordion that is collapsed by default, we need to set the 'active' property of the jQuery Accordion as false. Syntax: $("#demoAccordion"). accordion({ collapsible: true, active: false});

Which BS 5 attribute and value is used to create a collapse system?

Generally, we recommend using a button with the data-bs-target attribute. While not recommended from a semantic point of view, you can also use a link with the href attribute (and a role="button" ). In both cases, the data-bs-toggle="collapse" is required.


1 Answers

I ended up stumbling across this issue and added a CSS class for it:

.collapse-non-md {
    height: 0;
    display: none;
}
.collapse-non-md.collapsing {
    display: block;
}

@media (min-width: 992px) {
    .collapse-non-md {
        height: auto;
        display: block;
    }
}

Then I set the class of the element I wanted collapsed on screens below medium to collapse-non-md and voila, it's collapsed on small browsers and open on medium ones. It can still be opened and closed the normal way (the .in class overrides .collapse-non-md).

like image 90
Zane Avatar answered Sep 23 '22 05:09

Zane