class的流光效果

效果图:

代码示例

复制代码
<!DOCTYPE html>
<html lang="zh">
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title>Document</title>
		<style>
			* {
				margin: 0;
				padding: 0;
			}

			/* 流光效果 */
			.light {
				position: absolute;
				display: block;
			}

			.light:nth-child(1) {
				filter: hue-rotate(0deg);
				top: 0;
				left: 0;
				width: 100%;
				height: 3px;
				background: linear-gradient(90deg, transparent, #3a86ff);
				animation: animate1 8s linear infinite;
			}

			@keyframes animate1 {
				0% {
					left: -100%;
				}

				50%,
				100% {
					left: 100%;
				}
			}

			.light:nth-child(2) {
				filter: hue-rotate(60deg);
				top: -100%;
				right: 0;
				width: 3px;
				height: 100%;
				background: linear-gradient(180deg, transparent, #3a86ff);
				animation: animate2 8s linear infinite;
				animation-delay: 2s;
			}

			@keyframes animate2 {
				0% {
					top: -100%;
				}

				50%,
				100% {
					top: 100%;
				}
			}

			.light:nth-child(3) {
				filter: hue-rotate(120deg);
				bottom: 0;
				right: 0;
				width: 100%;
				background: linear-gradient(270deg, transparent, #3a86ff);
				animation: animate3 8s linear infinite;
				animation-delay: 4s;
			}

			@keyframes animate3 {
				0% {
					right: -100%;
					height: 3px;
				}

				50%,
				100% {
					height: 2px;
					right: 100%;
				}
			}

			.light:nth-child(4) {
				filter: hue-rotate(300deg);
				bottom: -100%;
				left: 0;
				width: 3px;
				height: 100%;
				background: linear-gradient(360deg, transparent, #3a86ff);
				animation: animate4 8s linear infinite;
				animation-delay: 6s;
			}

			@keyframes animate4 {
				0% {
					bottom: -100%;
				}

				50%,
				100% {
					bottom: 100%;
				}
			}

			.boxs {
				width: 100%;
				display: flex;
				justify-content: center;
				overflow: hidden;
			}

			.box {
				width: 300px;
				height: 300px;
				background-color: antiquewhite;
				text-align: center;

			}

			.box {
				position: relative;
				/* 让伪元素相对于.box定位 */
				overflow: hidden;
				/* 隐藏超出.box的部分 */
			}
		</style>
	</head>
	<body>

		<div class="boxs">
			
			<div class="box">
				<span class="light"></span><span class="light"></span><span class="light"></span><span class="light"></span>
				<p>流光效果</p>
			</div>
		</div>
	</body>
</html>

希望可以帮到大家

相关推荐
华仔啊1 小时前
图片标签用 img 还是 picture?很多人彻底弄混了!
前端·html
合作小小程序员小小店2 小时前
网页开发,在线%新版本旅游管理%系统,基于eclipse,html,css,jquery,servlet,jsp,mysql数据库
java·数据库·eclipse·html·intellij-idea·旅游·jsp
风止何安啊2 小时前
收到字节的短信:Trae SOLO上线了?尝尝鲜,浅浅做个音乐播放器
前端·html·trae
fruge2 小时前
低版本浏览器兼容方案:IE11 适配 ES6 语法与 CSS 新特性
前端·css·es6
今日无bug5 小时前
🥁 用 HTML5 打造你的第一个“敲击乐” Web 应用
html
李@十一₂⁰13 小时前
HTML 特殊字体符号
前端·html
han_17 小时前
前端高频面试题之CSS篇(一)
前端·css·面试
小小测试开发17 小时前
JMeter XPath2 Extractor用法全解析:精准提取XML/HTML响应数据
xml·jmeter·html
不会玩电脑的Xin.21 小时前
HTML + CSS
前端·css·html
能鈺CMS1 天前
内容付费系统全面解析:构建知识变现体系的最强工具(2025 SEO 深度专题)
大数据·人工智能·html