纯CSS实现文本或表格特效(连续滚动与首尾相连)

纯CSS实现文本连续向左滚动首尾相连

1.效果图:

2.实现代码:

kotlin 复制代码
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>纯CSS实现文本连续向左滚动首尾相连</title>

    <style>
      body {
        display: flex;
        justify-content: center;
        align-items: center;
        height: 100vh;
      }

      #wrap {
        overflow: hidden;
        position: relative;
        width: 600px;
        height: 20px;
        padding-bottom: 5px;
        border-bottom: 1px solid #cccccc;
        white-space: nowrap;
      }

      #slide {
        position: absolute;
        animation: slide 10s linear infinite;
      }

      @keyframes slide {
        0% {
          transform: translateX(0);
        }
        100% {
          transform: translateX(-50%);
        }
      }
    </style>
  </head>
  <body>
    <div id="wrap">
      <div id="slide">
        <span>111四季宛如一首无声的诗,一幅流动的画,在时光的长河中悄然流转,各自绽放着独特的魅力。</span>
        <span>111四季宛如一首无声的诗,一幅流动的画,在时光的长河中悄然流转,各自绽放着独特的魅力。</span>
      </div>
    </div>
  </body>
</html>

3.关键代码:

#wrap white-space: nowrap;

#slide animation: slide 10s linear infinite;

纯CSS实现表格连续向下滚动首尾相连

1.效果图:

2.实现代码:

kotlin 复制代码
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>纯CSS实现表格连续向下滚动首尾相连</title>

    <style>
      body {
        display: flex;
        justify-content: center;
        align-items: center;
        height: 100vh;
      }

      #wrap {
        overflow: hidden;
        position: relative;
        width: 500px;
        height: 80px;
        padding-bottom: 5px;
        border-bottom: 1px solid #cccccc;
     
      }
	  .MyTable{
		 width: 100%;
         height: 100%;
		}
      #slide {
        position: absolute;
        animation: slide 3s linear infinite;
      }

      @keyframes slide {
        0% {
          transform: translateY(-50%);
        }
        100% {
          transform: translateY(0);
        }
      }
	
    </style>
  </head>
  <body>
    <div id="wrap">
      <div id="slide">
		<table class="MyTable">
		  <thead>
			<tr>
			  <th>Column 1</th>
			  <th>Column 2</th>
			  <th>Column 3</th>
			  <th>Column 4</th>
			  <th>Column 5</th>
			  <th>Column 6</th>
			</tr>
		  </thead>
		  <tbody>
			<tr>
			  <td>Data 1</td>
			  <td>Data 2</td>
			  <td>Data 3</td>
			  <td>Data 11</td>
			  <td>Data 21</td>
			  <td>Data 31</td>
			</tr>
			<tr>
			  <td>Data 4</td>
			  <td>Data 5</td>
			  <td>Data 6</td>
			  <td>Data 41</td>
			  <td>Data 51</td>
			  <td>Data 61</td>
			</tr>
		  </tbody>
		</table>
		<table  class="MyTable">
		  <thead>
			<tr>
			  <th>Column 1</th>
			  <th>Column 2</th>
			  <th>Column 3</th>
			  <th>Column 4</th>
			  <th>Column 5</th>
			  <th>Column 6</th>
			</tr>
		  </thead>
		  <tbody>
			<tr>
			  <td>Data 1</td>
			  <td>Data 2</td>
			  <td>Data 3</td>
			  <td>Data 11</td>
			  <td>Data 21</td>
			  <td>Data 31</td>
			</tr>
			<tr>
			  <td>Data 4</td>
			  <td>Data 5</td>
			  <td>Data 6</td>
			  <td>Data 41</td>
			  <td>Data 51</td>
			  <td>Data 61</td>
			</tr>
		  </tbody>
		</table>
      </div>
    </div>
  </body>
</html>

3.关键代码:

#wrap height: 80px;
#slide animation: slide 3s linear infinite;

由于是想下滚动所以需要控制高度为一个table高度.

以上代码可以直接复制到菜鸟教程运行验证

gif制作工具

相关推荐
阿珊和她的猫2 小时前
v-scale-scree: 根据屏幕尺寸缩放内容
开发语言·前端·javascript
加班是不可能的,除非双倍日工资7 小时前
css预编译器实现星空背景图
前端·css·vue3
wyiyiyi7 小时前
【Web后端】Django、flask及其场景——以构建系统原型为例
前端·数据库·后端·python·django·flask
gnip8 小时前
vite和webpack打包结构控制
前端·javascript
excel8 小时前
在二维 Canvas 中模拟三角形绕 X、Y 轴旋转
前端
阿华的代码王国8 小时前
【Android】RecyclerView复用CheckBox的异常状态
android·xml·java·前端·后端
一条上岸小咸鱼8 小时前
Kotlin 基本数据类型(三):Booleans、Characters
android·前端·kotlin
Jimmy8 小时前
AI 代理是什么,其有助于我们实现更智能编程
前端·后端·ai编程
ZXT9 小时前
promise & async await总结
前端
Jerry说前后端9 小时前
RecyclerView 性能优化:从原理到实践的深度优化方案
android·前端·性能优化