I'm trying the make a horizontal scrollable bootstrap row. The row contains customer reviews wrapped in div's. The width of each testimonial div is 33.333%
.
white-space: nowrap
and display: inline-block
doesn't work.
What am I doing wrong?
<div class="row">
<div class="col-lg-12 text-center">
<div class="section-title">
<div class="testimonial_group">
<div class="testimonial">...</div>
<div class="testimonial">...</div>
<div class="testimonial">...</div>
<div class="testimonial">...</div>
...
</div>
</div>
</div>
</div>
Please check. Is it what you want to achieve?
/* The heart of the matter */
.testimonial-group > .row {
overflow-x: auto;
white-space: nowrap;
}
.testimonial-group > .row > .col-xs-4 {
display: inline-block;
float: none;
}
/* Decorations */
.col-xs-4 { color: #fff; font-size: 48px; padding-bottom: 20px; padding-top: 18px; text-align: center; }
.col-xs-4:nth-child(3n+1) { background: #c69; }
.col-xs-4:nth-child(3n+2) { background: #9c6; }
.col-xs-4:nth-child(3n+3) { background: #69c; }
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<div class="container testimonial-group">
<div class="row">
<div class="col-xs-4">1</div><!--
--><div class="col-xs-4">2</div><!--
--><div class="col-xs-4">3</div><!--
--><div class="col-xs-4">4</div><!--
--><div class="col-xs-4">5</div><!--
--><div class="col-xs-4">6</div><!--
--><div class="col-xs-4">7</div><!--
--><div class="col-xs-4">8</div><!--
--><div class="col-xs-4">9</div>
</div>
</div>
As commented by Hector, the inline-boxes solution works for Bootstrap 4 too, but requires to add display: block;
for .testimonial-group > .row
.
But Bartimaeus rightly notes that for Bootstrap 4 this result is more appropriate to achieve with the help of flexbox, adding the style classes provided for this: flex-nowrap
and overflow-auto
.
https://codepen.io/glebkema/pen/xxOgaMm
/* Decorations */
.col-4 { color: #fff; font-size: 48px; padding-bottom: 20px; padding-top: 18px; text-align: center; }
.col-4:nth-child(3n+1) { background: #c69; }
.col-4:nth-child(3n+2) { background: #9c6; }
.col-4:nth-child(3n+3) { background: #69c; }
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.6.2/css/bootstrap.min.css">
<div class="container">
<div class="row flex-nowrap overflow-auto">
<div class="col-4">1</div>
<div class="col-4">2</div>
<div class="col-4">3</div>
<div class="col-4">4</div>
<div class="col-4">5</div>
<div class="col-4">6</div>
<div class="col-4">7</div>
<div class="col-4">8</div>
<div class="col-4">9</div>
</div>
</div>