Bootstrap 4 Custom Carousel

Making a Responsive Multi-item Slider

Tom Michew
WDstack
3 min readAug 28, 2017

--

I’ve seen many variations of the Bootstrap Carousel, but for my purposes I needed a slider that met the following requirements:

Display multiple slides horizontally

Slide only one-at-a-time

Display a single slide on mobile

The Basic Bootstrap 4 Carousel

The default, out-of the-box slider, is designed to show a single slide at a time…

By using the grid within each carousel-item it’s easy to show multiple items per “slide”. For example, here is 3 items per slide using 2 carousel-items (a total of 6 slides)…

Bootstrap 4 Carousel — multiple items per slide

However, this didn’t work for my requirements, because it moves all 3 items when in moves to the next “slide”.

[1,2,3]… [4,5,6]…

In my case, I needed the carousel to move only a single slide at a time, but still show 3 slides at a time.

[1,2,3]… [2,3,4]… [3,4,5]…[4,5,6]…

For this, I found a helpful question on Stack Overflow. The accepted answer shows how to create a carousel that only advances a single slide at a time.

However, this still didn’t completely work for my requirements, because it wasn’t responsive, and the slides got squished across the screen on mobile. I unsuccessfully made more changes, that caused the items to stack vertically on mobile screens. Making it responsive is still a challenge.

This doesn’t work — the multiple items stack on mobile

So, I went back to the drawing board to find a Bootstrap 4 carousel that met my 3 requirements:

  • shows multiple items
  • advances only slider one at a time
  • shows only a single item on smaller screens

After several iterations, I found this implementation that uses CSS selectors determine which item(s) to show and make “active”. This also required a little jQuery hook into the Bootstrap 4 carousel “slide” event.

Responsive Multi-item Bootstrap 4 Carousel

And there it is! A responsive Bootstrap carousel that shows 4 items, slides one-at-a-time, and shows only a single slide on smaller screens.

❤ __ Tom Michew

--

--

Tom Michew
WDstack

Technical marketer, developer, startup guy #growthhacker @wdstack @codeplyapp