I have a 3-col-layout like
<div class="container">
<div class="row">
<div class="col-md-2" id="block1">#block1 .col-md-2</div>
<div class="col-md-2" id="block2">#block2 .col-md-2</div>
<div class="col-md-8" id="block3">#block3 .col-md-8</div>
</div>
</div>
----------------------------------------------------------------
| | | |
| | | |
| | | |
| | | |
| #block1 | #block2 | #block3 |
| .col-2 | .col-2 | .col-8 |
| | | |
| | | |
| | | |
| | | |
----------------------------------------------------------------
On small screens the columns slide one below the other:
-------------------------
| |
| |
| |
| |
| #block1 |
| .col-12 |
| |
| |
| |
| |
-------------------------
-------------------------
| |
| |
| |
| |
| #block2 |
| .col-12 |
| |
| |
| |
| |
-------------------------
-------------------------
| |
| |
| |
| |
| #block3 |
| .col-12 |
| |
| |
| |
| |
-------------------------
Now I want the first two columns to collapse like the typical Bootstrap navigation:
-------------------------
| #block1 .col-12 ≡ |
-------------------------
-------------------------
| #block2 .col-12 ≡ |
-------------------------
-------------------------
| |
| |
| |
| |
| |
| #block3 .col-12 |
| |
| |
| |
| |
-------------------------
I tried to "clone" it from the Bootstrap starter template, but could not found out, what exactly manages this behavior.
How to get DIVs collapsing automatically on small screens and provide a toggle button? Is it possible to do this by using only Bootstrap classes (without additional JS)?
Here you go with a solution https://jsfiddle.net/mhmvhsf6/
.col{
border: 1px dotted #000;
min-height: 50px;
}
.collapse {
height: 200px;
background: rgba(0,0,0,0.3);
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="container-fluid">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4 col">
<div class="navbar-header navbar-inverse">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4 col">
<div class="navbar-header navbar-inverse">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#collapse2">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse" id="collapse2">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4 col"></div>
</div>
</div>
Hope this will help you.
For Col-1 & col-2, content will go inside the collapse
class container.
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