Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Horizontally scrollable list of cards in Bootstrap

I am trying to create a horizontal list of cards where 3 cards are shown at a time and the other ones are horizontally scrollable, like this:

Horizontally scrollable list of cards

This can be done with CSS pretty easily, but I want to do this using Bootstrap. Bootstrap 4 ships with cards as popularized by material design and they are as easy to use as anything else in Bootstrap. For this example instead of cards it could also be regular divs.

The thing I am struggling with is creating a scrollable container of X cards (or divs) where 3 of them are shown at a time and the others overflow to the right and are scrollable. I am not sure how to use Bootstrap give the cards (or divs) a width so that 3 are shown at a time and the other ones lie next to them on the right.

like image 364
Lukas Avatar asked Mar 14 '16 16:03

Lukas


People also ask

How do I make a horizontal scrollable list in HTML?

For horizontal scrollable bar use the x and y-axis. Set the overflow-y: hidden; and overflow-x: auto; that will automatically hide the vertical scroll bar and present only the horizontal scrollbar. The white-space: nowrap; property is used to wrap text in a single line.

How do I make a horizontal scrollable menu?

Approach: Scrollable Horizontal Menu is used to scroll the horizontal navbar using CSS “overflow:auto” and “white-space: nowrap”. These two attributes are used to scroll the horizontal menu. You have to add HTML. You have to add CSS to the code.


Video Answer


1 Answers

Now that Bootstrap 4 Alpha 6 uses flexbox, this horizontal scrolling layout is much easier. You can simply use flex-row and flex-nowrap:

<div class="container-fluid">     <div class="row flex-row flex-nowrap">         <div class="col-3">             <div class="card card-block">Card</div>         </div>         <div class="col-3">             <div class="card card-block">Card</div>         </div>         <div class="col-3">             <div class="card card-block">Card</div>         </div>         <div class="col-3">             <div class="card card-block">Card</div>         </div>         ...     </div> </div> 

https://www.codeply.com/go/GoFQqQAFhN

Update 2019 Bootstrap 4.3+

The above method still works, or you can use the flexbox utils in the container of the cards: https://www.codeply.com/go/PF4APyGj7F

like image 113
Zim Avatar answered Sep 28 '22 07:09

Zim