I need to have a row with 8 columns in a large device, but then the lower number columns in a smaller device.
The bootstrap uses the 12-grid system and by default, you have options of col-1
, col-2
, col-3
, col-4
, col-6
and col-12
. So, it is not possible to have a row with 8 columns.
Although there are plenty of workarounds and I've tested all manner of them (like: this and this), One of the up-voted StackOverflow's answers is this.
Based on the mentioned answer, Although the following solution works perfectly, it does not work if I use bootstrap's predefined classes like col-md-3
, col-sm-4
, etc.
.col-xs-8r,
.col-sm-8r,
.col-md-8r,
.col-lg-8r {
position: relative;
min-height: 1px;
padding-right: 15px;
padding-left: 15px;
}
.col-xs-8r {
width: 12.5%;
float: left;
}
@media (min-width: 768px) {
.col-sm-8r {
width: 12.5%;
float: left;
}
}
@media (min-width: 992px) {
.col-md-8r {
width: 12.5%;
float: left;
}
}
@media (min-width: 1200px) {
.col-lg-8r {
width: 12.5%;
float: left;
}
}
The following code words perfectly.
<div class="row">
<div class="col-lg-8r">
...
</div>
</div>
If I add another col-sm-*
or col-md-*
, the custom column (col-lg-8r
) does not work.
<div class="row">
<div class="col-sm-4 col-md-3 col-lg-8r">
...
</div>
</div>
PS I don't like to use the nested columns and rows workaround.
Bootstrap version: 4.4.1