Pure css to achieve carousel effect

Pure css to achieve carousel effect

Don't say much, just go to the code

* {
    
    
            margin: 0;
            padding: 0;
        }

        .container {
    
    
            margin:300px auto;
            height: 400px;
            width: 1146px;
            overflow: hidden;
        }

        /* .wrap */
        .wrap {
    
    
            position: relative;
            width:10000px;
            left: 0px;
            animation: animateImg ease 5s infinite normal;
        }

        /* 图片大小 */
        .wrap img {
    
    
            width: 1146px;
            float: left;
            height: 400px;
            display: block;
        }

        /* 动画 */
        @keyframes animateImg {
    
    
            0% {
    
    
                left: 0px;
            }

            20% {
    
    
                left: -0px;
            }

            40% {
    
    
                left: -1146px;
            }

            60% {
    
    
                left: -2292px;
            }

            80% {
    
    
                left: -3438px;
            }

            100% {
    
    
                left: 0px;
            }
        }

Animation effect pixels are modified according to their own picture size

<div class="container">
        <div class="wrap">
            <img src="images/banner1.jpg"alt="" />
            <img src="images/banner2.jpg"alt="" />
            <img src="images/banner3.jpg"alt="" />
            <img src="images/banner4.jpg"alt="" />
        </div>

Guess you like

Origin blog.csdn.net/Web_chicken/article/details/108576141