标签搜索

css实现轮播图

默然
2021-07-16 / 0 评论 / 66 阅读 / 正在检测是否收录...

css实现轮播图效果图

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>CSS轮播图</title>
    <style>
        /* 轮播 */
        .slide {
            position: relative;
            margin: auto;
            width: 1200px;
            height: 600px;
            text-align: center;
            font-family: Arial;
            color: #FFF;
            overflow: hidden;
        }

        .slide ul {
            margin: 10px 0;
            padding: 0;
            width: 9999px;
            transition: all 0.5s;
        }

        /*自动播放*/
        .slide .slide-auto {
            animation: marginLeft 6.5s infinite;
        }

        .slide li {
            float: left;
            width: 1200px;
            height: 600px;
            list-style: none;
            line-height: 600px;
            font-size: 36px;
        }

        .slide li:nth-child(1) {
            background: red;
        }

        .slide li:nth-child(2) {
            background: green;
        }

        .slide li:nth-child(3) {
            background: purple;
        }

        @keyframes marginLeft {
            0% {
                margin-left: 0;
            }

            28.5% {
                margin-left: 0;
            }

            33.3% {
                margin-left: -1200px;
            }

            62% {
                margin-left: -1200px;
            }

            66.7% {
                margin-left: -2400px;
            }

            95.2% {
                margin-left: -2400px;
            }

            100% {
                margin-left: 0;
            }
        }
    </style>
</head>

<body>
    <!-- 轮播 -->
    <div class="slide">
        <ul class="slide-auto">
            <li>第一个</li>
            <li>第二个</li>
            <li>第三个</li>
        </ul>
    </div>
</body>

</html>
1

评论 (0)

取消