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.
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.
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.
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});
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.
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
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With