微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

怎么使用css实现文字循环滚动效果

今天小编给大家分享一下怎么使用css实现文字循环滚动效果的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。

1.首先创建一个html文件

2.在html文件添加HTML代码架构。

<!DOCTYPE html>
<html>
    <head>
<Meta charset="UTF-8">
        <title>文字循环滚动效果</title>
    </head>
    <body>
    </body>
</html>

3.然后在HTML代码架构中的body标签里面使用div和p标签设计一段文字

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

4.在html架构中的html标签里面添加style标签并写入css样式代码来实现文字滚动效果

<style>
 * {
            margin: 0;
            padding: 0;
        }
 
        .Box {
            width: 300px;
            margin: 0 auto;
            border: 1px solid #ff6700;
            overflow: hidden;
        }
 
        .animate {
            padding-left: 20px;
            font-size: 12px;
            color: #000;
            display: inline-block;
            white-space: Nowrap;
            animation: 10s wordsLoop linear infinite normal;
        }
 
        @keyframes wordsLoop {
            0% {
                transform: translateX(200px);
                -webkit-transform: translateX(200px);
            }
            100% {
                transform: translateX(-100%);
                -webkit-transform: translateX(-100%);
            }
        }
 
        @-webkit-keyframes wordsLoop {
            0% {
                transform: translateX(200px);
                -webkit-transform: translateX(200px);
            }
            100% {
                transform: translateX(-100%);
                -webkit-transform: translateX(-100%);
            }
        }
</style>

5.最后可通过浏览器方式阅读html文件查看设计效果

完整示例代码如下:

<!DOCTYPE html>
<html>
<head>
<Meta charset="utf-8"> 
<title>文字循环滚动效果</title> 
<style>
 * {
            margin: 0;
            padding: 0;
        }
 
        .Box {
            width: 300px;
            margin: 0 auto;
            border: 1px solid #ff6700;
            overflow: hidden;
        }
 
        .animate {
            padding-left: 20px;
            font-size: 12px;
            color: #000;
            display: inline-block;
            white-space: Nowrap;
            animation: 10s wordsLoop linear infinite normal;
        }
 
        @keyframes wordsLoop {
            0% {
                transform: translateX(200px);
                -webkit-transform: translateX(200px);
            }
            100% {
                transform: translateX(-100%);
                -webkit-transform: translateX(-100%);
            }
        }
 
        @-webkit-keyframes wordsLoop {
            0% {
                transform: translateX(200px);
                -webkit-transform: translateX(200px);
            }
            100% {
                transform: translateX(-100%);
                -webkit-transform: translateX(-100%);
            }
        }
</style>
</head>
<body>
  <div class="Box">
    <p class="animate">
        文字滚动的内容
    </p>
<div>
</body>
</html>

以上就是“怎么使用css实现文字循环滚动效果”这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注编程之家行业资讯频道。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐