纯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制作工具

相关推荐
慕容卡卡9 小时前
Claude 使用神器(web页面)--CloudCLI UI
java·开发语言·前端·人工智能·ui·spring cloud
JarvanMo9 小时前
搞懂这 5 个 AI 术语,你就超过了 90% 的人
前端·后端
IT_陈寒9 小时前
Vite的HMR怎么突然失效了?原来是我太年轻
前端·人工智能·后端
ZC跨境爬虫9 小时前
Apple官网复刻第二阶段day_6:(统一页脚模块封装+CSS公共复用体系落地)
前端·css·ui·重构·html
恋猫de小郭9 小时前
Flutter 凉了没?Flutter 2026 的未来行程和规划,一些有趣的变化
android·前端·flutter
Beginner x_u9 小时前
前端手动实现大文件分片上传调度层:分片计算、并发上传与断点续传
前端·状态模式·断点续传·大文件分片上传
胖纳特9 小时前
Nextcloud 文件预览困局与破局:集成 BaseMetas Fileview 实现全格式在线预览
前端·后端
一个心烑9 小时前
Layui结合springboot读取返回值,前端展示简单示例
前端·spring boot·layui
天天向上10249 小时前
openlayers 加载Shapefile文件
前端·javascript·html
亿元程序员9 小时前
手工拼豆有风险?手把手教你开发个电子版的
前端