Question

Is it possible to stack multiple slideshows carousels the same way you can stack images?

In the code below, I have stacked five, vertically scrollable, images. I would like to replace each of these images with a slideshow carousel. In other words, I would like five stacked, horizontally scrollable slideshows, using just HTML and CSS (No JavaScript).

Does anyone know how that can be done?

Thanks!!

HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>All about Nothing</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div>
        <section class="blur-container SlideShow-1">
        </section>
        <section class="blur-container SlideShow-2">
        </section>
        <section class="blur-container SlideShow-3">
        </section>
        <section class="blur-container SlideShow-4">
        </section>
        <section class="blur-container SlideShow-5">
        </section>
    </div>
</body>
</html>

CSS Code:

section {
  height: 100vh;
  display: flex;
  position: relative;
}

.blur-container {
  background-size: cover !important;
  background-position: center !important;
  background-attachment: fixed !important;

  &::before,
  &::after {
    top: 0px;
    left: 0px;
    content: '';
    width: 100%;
    height: 100%;
    display: block;
    position: absolute;
  }
}

.SlideShow-1 {
  background: url('https://arthur.io/img/art/jpg/000017344d60348e7/monika-bielskyte/untitled-27/large-2x/monika-bielskyte--untitled-27.webp');
}

.SlideShow-2 {
  background: url('https://arthur.io/img/art/jpg/000017344d60398be/monika-bielskyte/untitled-29/large-2x/monika-bielskyte--untitled-29.webp');
}

.SlideShow-3 {
  background: url('https://arthur.io/img/art/jpg/0017344d60a261291/monika-bielskyte/untitled-63/large-2x/monika-bielskyte--untitled-63.webp');
}

.SlideShow-4 {
  background: url('https://arthur.io/img/art/jpg/00017344d603531b3/monika-bielskyte/untitled-19/large-2x/monika-bielskyte--untitled-19.webp');
}

.SlideShow-5 {
  background: url('https://arthur.io/img/art/jpg/000017344d60398be/monika-bielskyte/untitled-29/large-2x/monika-bielskyte--untitled-29.webp');
}

Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

KFSys
Site Moderator
Site Moderator badge
December 27, 2023

Heya,

Creating stacked, horizontally scrollable slideshows using only HTML and CSS (without JavaScript) involves a bit of creativity in your CSS design. While JavaScript is typically used for interactive components like slideshows, it’s possible to create a basic version with CSS only.

Here is an example:

  1. HTML Structure: You will need to modify your HTML to include multiple images (or div elements representing slides) inside each slideshow section.

  2. CSS Styling: Use CSS to style these slideshows to be horizontally scrollable. This involves setting a container to display its contents in a row and allow for overflow in the horizontal direction.

HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>All about Nothing</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div>
        <section class="blur-container slideshow">
            <div class="slide slide1"></div>
            <div class="slide slide2"></div>
            <!-- Add more slides as needed -->
        </section>
        <!-- Repeat for each slideshow -->
        <!-- ... -->
    </div>
</body>
</html>

CSS:

section.slideshow {
    height: 100vh;
    display: flex;
    overflow-x: auto; /* Enable horizontal scrolling */
    scroll-snap-type: x mandatory; /* Optional: for smoother scrolling */
}

.slide {
    flex: 0 0 auto; /* Do not grow, do not shrink, and maintain its size */
    width: 100%; /* Set the width of each slide */
    height: 100%;
    scroll-snap-align: start; /* Optional: for smoother scrolling */
    background-size: cover;
    background-position: center;
    position: relative;
}

.slide1 {
    background-image: url('...'); /* Your first slide image */
}

.slide2 {
    background-image: url('...'); /* Your second slide image */
}

/* Add more slide classes for different backgrounds */

In this setup, each section represents a slideshow, and the div elements inside are individual slides. The overflow-x: auto CSS property on the section allows horizontal scrolling. Each slide is set to not grow or shrink and maintain its width, ensuring they line up horizontally.

You can add as many slides as you want within each section, and you can style them with different background images or content as needed. Remember that this is a basic setup and won’t provide advanced features like automatic sliding or navigation buttons, which typically require JavaScript.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel