使用css实现自动轮播

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<style>
    .box {
        position: absolute;
        overflow: hidden;
        width: 200px;
        height: 200px;
        left: 50%;
        top: 50%;
        text-align: center;
        font-size: 100px;
        line-height: 200px;
        font-weight: 700;
        border: 1px solid black;
        transform: translate(-50%, -50%);
    }
    .box .content {
        width: 1000px;
        animation: solider 12s infinite;
        /*动画名称 运行时间 无限轮播  */
    }
    .box .content .item {
        float: left;
        width: 200px;
    }
    @keyframes solider {
        0% {
            margin-left: 0px;
        }
        25% {
            margin-left: -200px;
        }
        50% {
            margin-left: -400px;
        }
        75% {
            margin-left: -600px;
        }
        100% {
            margin-left: -800px;
        }
    }
</style>

<body>
    <div class="box">
        <div class="content">
            <div class="item">
                1
            </div>
            <div class="item">
                2
            </div>
            <div class="item">
                3
            </div>
            <div class="item">
                4
            </div>
            <div class="item">
                1
            </div>
        </div>
    </div>
</body>

</html>

猜你喜欢

转载自blog.csdn.net/lzh5997/article/details/80389690