纯css实现上下滚动

5,171 阅读1分钟
<!doctype html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>纯css实现文字循环滚动效果</title>
    <style type="text/css">
        * {
            margin: 0;
            padding: 0;
        }

        .box {
            width: 300px;
            margin: 0 auto;
            border: 1px solid #ff6700;
            overflow: hidden;
            height: 50px;
        }

        .animate {
            padding-left: 20px;
            font-size: 12px;
            color: #000;
            display: inline-block;
            white-space: nowrap;
            animation: 2s wordsLoop linear infinite normal;
            height: 20px;
        }

        .animate p {
            margin-top: 10px;
            ;
        }



        @-webkit-keyframes wordsLoop {
            0% {
                transform: translateY(50px);

            }

            100% {
                transform: translateY(-80px);
                -webkit-transform: translateY(-80px);
            }
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="animate">
            <p>文字滚动的内容</p>
            <p>文字滚动的内容</p>
            <p>文字滚动的内容</p>
            <p>文字滚动的内容</p>
        </div>
    </div>
</body>

</html>