Horizontal scrollable div's in a bootstrap row

HtmlCssListTwitter Bootstrap-3Scrollable

Html Problem Overview


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>

Html Solutions


Solution 1 - Html

Please check. Is it what you want to achieve?

horizontal scrolling

CodePen  •  JSFiddle

/* 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; }
.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.3.7/css/bootstrap.min.css">

<div class="container testimonial-group">
  <div class="row text-center">
    <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>

for Bootstrap 4

Thanks Hector for the comment!

https://codepen.io/glebkema/pen/xxOgaMm

/* The heart of the matter */
.testimonial-group > .row {
  display: block;
  overflow-x: auto;
  white-space: nowrap;
}
.testimonial-group > .row > .col-4 {
  display: inline-block;
}

/* Decorations */
.col-4 { color: #fff; font-size: 48px; padding-bottom: 20px; padding-top: 18px; }
.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.5.0/css/bootstrap.min.css">

<div class="container testimonial-group">
  <div class="row text-center">
    <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>

Solution 2 - Html

In Bootstrap 4 you will need to add

flex-wrap: nowrap;

to

.testimonial-group > .row

in addition to Gleb's answer

Solution 3 - Html

The Flexbox Method

/* The heart of the matter */
.testimonial-group > .row {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
}
.testimonial-group > .row > .col-xs-4 {
  flex: 0 0 auto;
}

/* Decorations */
.col-xs-4 { color: #fff; font-size: 48px; padding-bottom: 20px; padding-top: 18px; }
.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.3.7/css/bootstrap.min.css">

<div class="container testimonial-group">
  <div class="row text-center">
    <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>

Solution 4 - Html

Try this:

section-title {
  width: 100%; 
  overflow-x: scroll(or auto);
} 

Look at the spec here.

Solution 5 - Html

put these lines in your CSS file

.section-title {
  overflow: scroll;
  overflow-x: scroll;
  overflow-y:hidden
}

the x is for horizontal and y is for vertical, apply class code in parent div in which many div's are nested.

Solution 6 - Html

You can use:

class="text-nowrap overflow-auto"

Consider this example:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">

<div class="list-group list-group-horizontal text-nowrap overflow-auto">
  <a href="#" class="list-group-item list-group-item-action active">
    Cras justo odio
  </a>
  <a href="#" class="list-group-item list-group-item-action">Dapibus ac facilisis in</a>
  <a href="#" class="list-group-item list-group-item-action">Morbi leo risus</a>
  <a href="#" class="list-group-item list-group-item-action">Porta ac consectetur ac</a>
  <a href="#" class="list-group-item list-group-item-action disabled" tabindex="-1" aria-disabled="true">Vestibulum at eros</a>
</div>

To accomplish the desired result without any css or all the unneeded divs: getbootstrap.com/list-group.

Solution 7 - Html

I don't understand why so much struggling with all these no-wrap and flex attributes which actually only work on child elements with no text. In case there is text inside the child elements, the

white-space: nowrap;

attribute makes the whole text expand in one line having as a result text to overlap everything else and break the whole layout.

The solution is much simpler. Simply, give to the parent element the following

display: flex;
overflow-x: auto;

and then to the child elements the following

min-width: 25%;

Note: 25% for col size 3, 33.33333% for col size 4, 50% for col size 6 and so on. And there you have it. A horizontally scrollable div based on bootstrap cols for the layout.

Here is a clean sample. Fiddle

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCodehan25View Question on Stackoverflow
Solution 1 - HtmlGleb KemarskyView Answer on Stackoverflow
Solution 2 - HtmlMartin K.View Answer on Stackoverflow
Solution 3 - HtmlNandeep BarochiyaView Answer on Stackoverflow
Solution 4 - HtmlVally PepyakoView Answer on Stackoverflow
Solution 5 - HtmlAbhinash MajhiView Answer on Stackoverflow
Solution 6 - HtmljohnmweiszView Answer on Stackoverflow
Solution 7 - HtmlSmolikasView Answer on Stackoverflow