Reputation: 1437
Initially I wanted to do this layout in bootstrap 4, but now I almost sure that it's impossible without using some hacks like doubling content and then hiding it for mobile/desktop or using javaScript.
For desktop:
+---+---+
| 1 | |
+---+ +
| 3 | |
+---+ 2 +
| 4 | |
+---+ +
| 5 | |
+--+----+
For smartphones:
+---+
| 1 |
+---+
| 3 |
+---+
| 2 |
+---+
| 4 |
+---+
| 5 |
+---+
The main problem that I facing with Bootstrap 4 is an equal height of columns, which I don't know what to do with. I can, of course, do it in two nested columns, but then I cannot rearrange order how I want.
In bootstrap 3 I could do it like here in example #9: https://www.bootply.com/siUcTuNhUy But how to do it in bootstrap 4?
Please advise what am I missing.
Upvotes: 1
Views: 90
Reputation: 38
Not sure about the alternatives in Bootstrap, but this can be done using CSS grid.
You can find the codepen with the solution here - https://codepen.io/vishwaovi/pen/RqKaMv?editors=1100
HTML
<div class="main">
<div class="section section1"> 1 </div>
<div class="section section2"> 2 </div>
<div class="section section3"> 3 </div>
<div class="section section4"> 4 </div>
<div class="section section5"> 5 </div>
</div>
CSS
.main {
display:grid;
grid-template-columns: 1fr 1fr; // defining a two column grid
}
.section2{
grid-column: 2;
grid-row: span 4;
}
@media (max-width:800px){
.main{
grid-template-columns: 1fr;
}
.section2{
grid-column: 1;
grid-row: 3 /span 1;
}
}
Upvotes: 1
Reputation: 4712
Maybe this is useful.
To meet your request for the smartphone layout, I used flexbox (with Bootstrap 4 grid):
.grid .stacked {
width: 48%
}
.grid .section {
background: #069;
margin: 5px auto;
text-align: center;
color: #fff;
WIDTH: 100%;
}
@media (max-width: 575px) {
.grid .stacked {
width: 100%
}
.stacked .section:nth-child(1) {
order: 1;
}
.stacked .section:nth-child(2) {
background: #c00;
order: 3;
}
.stacked .section:nth-child(3) {
order: 2;
}
.stacked .section:nth-child(4) {
order: 4;
}
.stacked .section:nth-child(5) {
order: 5;
}
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<div class="container">
<div class="grid d-flex flex-wrap">
<div class="stacked d-flex flex-column">
<div class="section col-xs-12">1</div>
<div class="section col-xs-12 d-block d-sm-none">2</div>
<div class="section col-xs-12">3</div>
<div class="section col-xs-12">4</div>
<div class="section col-xs-12">5</div>
</div>
<div class="section col-xs-12 col-sm-6 d-none d-sm-block">2</div>
</div>
</div>
Upvotes: 1