CSS: Continuous Automated Slide Transitions

What CSS code do I need to incorporate into my code to create a continuous Slider Animation? I want the pictures to slide automatically one by one, with a specified time interval between each slide when not on hover. The hover function is already included in the CSS, so there's no need to add it again. You can easily run it here to see it in action.

Please run the code in full-screen mode.

HTML:

   /* Cool Header Design */
#main-row102
.wrapper {
  width: auto;
  position: fixed;
  overflow: hidden;
}
.row {
  display: flex;
  width: 100%;
  margin: 0px;
}

.col-xs-3 {
  padding: 0px;
  border: 1px solid black;
  display: inline-block;
  width: calc(100% - 30px);
  height: 340px;
  background: transparent;
  z-index: 1;
}

.wrapper-background {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index : 0;
  transition: background 5s;
}

.wrapper:hover .col-xs-3 {
  background: none;
}
.wrapper:hover .col-xs-3:hover {
  background: red;
}
/* More CSS styles go here... */

<div id="main-row-102"></div>
<div class="wrapper">
  <div class="row">
    <div class="col-xs-3"></div>
    <div class="wrapper-background"></div>
    <div class="col-xs-3"></div>
    <div class="wrapper-background"></div>
    <div class="col-xs-3"></div>
    <div class="wrapper-background"></div>
    <div class="col-xs-3"></div>
    <div class="wrapper-background"></div>
  </div>
  <div class="row">
    <div class="col-xs-3"></div>
    <div class="wrapper-background"></div>
    <div class="col-xs-3"></div>
    <div class="wrapper-background"></div>
    <div class="col-xs-3"></div>
    <div class="wrapper-background"></div>
    <div class="col-xs-3"></div>
    <div class="wrapper-background"></div>
  </div>
</div>

Answer №1

Create a similar layout for the background and add animation effects when hovering over columns.

#slider {
    background: #000;
    box-shadow: 1px 1px 5px rgba(0,0,0,0.7);
    width:100%;
    margin-top: 2%;
    overflow: visible;
    position: relative;
    text-align: center;
    border-radius: 5px;
    margin-bottom: 40px;
}

/* Hide everything out of slider */
#mask {
    overflow: hidden;
    height: 240px;
}

/* The list of the images */

#slider ul {
    margin: 0;
    padding: 0;
    position: relative;
}

#slider li {
    width: 980px;
    height: 240px;
    position: absolute;
    top: -245px;/* Initial position  (out of slider) */
    list-style: none;
}

.slider-img {
    border-radius: 5px;
}

#slider li.firstanimation {
   animation: cycle 20s linear infinite;
}

#slider li.secondanimation {
   animation: cycletwo 20s linear infinite;
}

#slider li.thirdanimation {
   animation: cyclethree 20s linear infinite;
}

#slider li.fourthanimation {
   animation: cyclefour 20s linear infinite;
}

/* Animation */

@keyframes cycle {
   0%  { top: 0px; } /* When animation starts we already see the first image */
   5%  { top: 0px; } /* Start position */
   20% { top: 0px; opacity:1; z-index:0; } /* From 5% to 20 % (3 secs) image visible */
   25% { top: 245px; opacity: 0; z-index: 0; } /* From 20% to 25% (1 sec) entrance of the image*/
   26% { top: -245px; opacity: 0; z-index: -1; } /* Return to the starting position out of mask */
   90% { top: -245px; opacity: 0; z-index: 0; }
   95% { top: -245px; opacity: 0; } /* From 95% to 100% (1 sec) – entrance */
   100%{ top: 0px; opacity: 1; }
}

@keyframes cycletwo {
   0%  { top: -245px; opacity: 0; } /* The starting position out of the mask */
   20% { top: -245px; opacity: 0; }/* Start move from 20% */
   25% { top: 0px; opacity: 1; }
   30% { top: 0px; opacity: 1; }  /* From 25% to 30% (in 1 sec) — entrance*/
   45% { top: 0px; opacity: 1; z-index: 0; }   /* From 30% to 45% (3 sec) image is visible */
   50% { top: 245px; opacity: 0; z-index: 0; } /* From 45% to 50% (1 sec)— exit */
   95% { top: -245px; opacity: 0; z-index: -1; }   /* Return to the starting position out of mask */
   100%{ top: -245px; opacity: 0; z-index: -1; }
}

@keyframes cyclethree {
   0%  { top: -245px; opacity: 0; }
   45% { top: -245px; opacity: 0; }
   50% { top: 0px; opacity: 1; }
   55% { top: 0px; opacity: 1; }
   70% { top: 0px; opacity: 1; }
   75% { top: 245px; opacity: 0; z-index: 0; }
   76% { top: -245px; opacity: 0; z-index: -1; }
   100%{ top: -245px; opacity: 0; z-index: -1; }
}

@keyframes cyclefour {
    0%  { top: -245px; opacity: 0; }
    70% { top: -245px; opacity: 0; }
    75% { top: 0px; opacity: 1; }
    80% { top: 0px; opacity: 1; }
    95% { top: 0px; opacity: 1; z-index: 0; }
    100%{ top: 245px; opacity: 0; z-index: 0; }
}
<div id="slider">
                        <div id="mask"> 
                            <ul>
                                <li id="first" class="firstanimation">
                                    <img class="slider-img"  src="https://coverfiles.alphacoders.com/455/45585.jpg"/>
                                </li>

                                 <li id="second" class="secondanimation">
                                    <img class="slider-img"  src="http://www.tuellaneinfantschool.org.uk/wp-content/uploads/2013/10/foxes-header.jpg"/>
                                 </li>

                                 <li id="third" class="thirdanimation">
                                    <img class="slider-img"  src="https://wallpapers.pub/web/wallpapers/fox-animal-wallpaper-hd/1500x500.jpg"/>
                                 </li>

                                 <li id="fourth" class="fourthanimation">
                                    <img class="slider-img"  src="https://coverfiles.alphacoders.com/484/48440.jpg"/>
                                 </li>
                            </ul>
                         </div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can I prevent a span in CSS from stretching its parent element?

Utilizing the twitter bootstrap thumbnails successfully, we have implemented a description feature inspired by the bootstrap documentation. The distinction lies in our decision not to specify a size (e.g., .span4) for our thumbnails; instead, the content d ...

The content is unclipped with a border-radius and hidden overflow

As I work on incorporating stylistic text inside rounded divs, I encounter a challenge where the text touches the top of the container. While I have successfully managed to customize various content elements such as nested divs and background images, this ...

The background image fails to display properly on the server in Next.js

Hello, I'm currently using NextJs and I have a challenge. I want to set a background image on the body element that is rendered server-side. Below you'll find my code snippets: First, here is my App.js: import BodyStyle from '@components/Bo ...

Challenges in customizing the bootstrap navigation bar links

Having an issue with the bootstrap navbar link displaying on small devices. Here is the template I'm using: https://i.sstatic.net/jSy1b.png The last item is displaying in two lines. ...

Navigating to the most recent item within ng-repeat (AngularJS or JavaScript)

I am working on a feature where posts are displayed using ng-repeat in a div, and users can enter new posts in an input box. The posts are sorted so that the latest one appears at the bottom. After adding a new post, I want to automatically scroll down t ...

The Proper Usage of Commas in CSS

Check out this CSS code snippet. .form-field {min-height: 20px; margin-bottom: 10px; padding-top: 4px; width: 80px;} .form-field TEXTAREA, INPUT[type='text'] {position: absolute; left: 100px; top: 0px; height: 15px;} .form-field TEXTAREA {height ...

What could be causing my Bootstrap 5 hover effect to malfunction?

Can anyone help with changing the hover effect of a bootstrap button in my code? Here's the HTML: <button type="button" class=" btn btn-dark">Sign Up</button> And here's the CSS I tried: .btn-dark:hover { color: ...

Is there a way to postpone the mouseover event for vertical tabs?

While this may seem like a simple question to some, my programming skills are not quite up to par. I am seeking help from someone who can assist me. My goal is to delay the mouseover event on vertical tabs so that users can jump directly from tab 1 to ta ...

Center a vertically aligned element following a heading, with the content dynamically generated and enclosed in a fixed container

My mind is racing with this problem and I'm not sure if it's solvable, but before throwing in the towel, I thought I'd seek help from the Internet Gods. Here's a visual representation of what I'm aiming for: I want the text to al ...

Adjust the appearance of the scrollbar with custom CSS, but be aware that the typical methods may not be effective in

I am interested in customizing the appearance of scrollbars on my website. After coming across this tutorial on W3Schools titled W3S: How TO - Custom Scrollbar, I successfully applied the changes on Chrome, but unfortunately, it did not work on Firefox. H ...

Utilize UI Kit to incorporate fluid margins dynamically

How can I dynamically add internal margins between cards in a responsive layout? The following code ensures responsiveness: Large Screens display 4 Cards. Medium Screens display 3 Cards. Small Screens display 2 Cards. Micro Screens display 1 Card. &l ...

What is the best way to incorporate an animation into my text bubble? Specifically for a Twitch Alert, such as a bits alert

I'm attempting to customize my Twitch Alert in Streamlabs using code. Is there a way to incorporate animation into the text balloon? I've looked for tutorials or guides but haven't had any luck, so I could use some guidance. CSS #alert-use ...

What is the best way to ensure the main container fills the entire screen?

Given: Bootstrap 5.1 Visual Studio 2022 Professional Edition Blazor Server Application How do I modify the container to occupy the entire screen without any margins? <div class="container bg-primary"> Hello World! </div> Thi ...

showing text style that is only specified on the server, not by the client

I am in the process of creating a new website that offers SMS services through clickatell. This website includes various font families that may not be defined on the client's computer. For instance, if the site is accessed from a different computer, t ...

Using CSS or JavaScript to trigger events while scrolling with touch

Imagine a scenario where multiple boxes are stacked on top of each other: <div style="width: 100%; height: 100px; background-color: red"> stuff </div> By clicking or touching them, the background color can be easily changed using CSS (:hover, ...

Is there a way to update the content of both spans within a button component that is styled using styled-components in React?

I am interested in creating a unique button component using HTML code like the following: <button class="button_57" role="button"> <span class="text">Button</span> <span>Alternate text</span> ...

Is it possible to make side elements expand to occupy the remaining screen space beyond the container?

This is what it's supposed to look like: The goal here is to have the red element on the left expand to fill the remaining space beside its content, as well as the grey on the right. I am utilizing bootstrap which means the center elements occupy 117 ...

Scrollbar generation causing spacing issues in Internet Explorer

So I've been working on implementing a scrollable div with a specific code overflow: auto; However, for some reason, when viewed in Internet Explorer, the scroll creates an unexpected margin on the right side. It functions properly on both Chrome an ...

Creating a search form in Bootstrap 4 that is centered and expands to full width only on small screens

I'm currently working with a bootstrap v.4 navbar that has 3 elements in it. I've managed to align the elements evenly so that the search bar is centered in the navbar. However, when it collapses it takes up the full width of the screen. Here is ...

Singularize button/solo in the center

How can I make this button align perfectly center on both PC and Mobile as a container? I have attempted the following CSS and HTML code: <section id="jour"> <div class="container"> <button class="btn1">Jeudi 12</button> ...