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>

希望可以帮到大家

相关推荐
m0_5474866612 小时前
《HTML+CSS+JavaScript+Vue前端开发技术教程》全套PPT课件
javascript·css·html
gCode Teacher 格码致知13 小时前
Javascript技术:CSS 中rem、vh 和 px各有其最佳适用场景-由Deepseek产生
开发语言·javascript·css
fastjson_13 小时前
Edge浏览器开启IE兼容模式
javascript·edge·html
qq_4198540516 小时前
css filter
前端·javascript·css
艾伦野鸽ggg17 小时前
web 组大一下第二次考核
前端·css·html
川石课堂软件测试18 小时前
APP自动化测试|高级手势操作&toast操作
css·功能测试·测试工具·microsoft·fiddler·单元测试·harmonyos
用户0595401744619 小时前
Playwright 网络拦截踩坑实录:我花了 3 小时才搞懂数据持久化验证的正确姿势
前端·css
货拉拉技术19 小时前
Huolala Figma MCP 原理与实践
人工智能·前端框架·html
TA远方2 天前
【HTML】JavaScript Canvas 图像截取与保存完整指南
前端·javascript·html·canvas·截图·截取
feixing_fx2 天前
选择器的威力——深入理解优先级计算与层叠规则
开发语言·前端·css·前端框架·html