当前位置: 首页 > news >正文

【css酷炫效果】纯css实现液体按钮效果

【css酷炫效果】纯css实现液体按钮效果

  • 创作背景
  • html结构
  • css样式
  • 完整代码
    • 基础版
    • 进阶版(动态边框)
  • 效果图

想直接拿走的老板,链接放在这里:https://download.csdn.net/download/u011561335/90490497

创作随缘,不定时更新。

创作背景

刚看到csdn出活动了,赶时间,直接上代码。

html结构

<button class="liquid-btn-1">Hover Me</button>

css样式

.liquid-btn-1 {
  padding: 15px 30px;
  font-size: 1.2rem;
  background: #2196f3;
  color: white;
  border: none;
  border-radius: 50px;
  position: relative;
  overflow: hidden;
  transition: 0.8s;
  cursor: pointer;
}

.liquid-btn-1:hover {
  background: #1565c0;
  box-shadow: 0 0 20px rgba(33,150,243,0.5);
}

.liquid-btn-1::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255,255,255,0.4),
    transparent
  );
  transition: 0.8s;
}

.liquid-btn-1:hover::before {
  left: 100%;
}

完整代码

基础版

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CSS Liquid Button</title>
    <style>
	.liquid-btn-1 {
	  padding: 15px 30px;
	  font-size: 1.2rem;
	  background: #2196f3;
	  color: white;
	  border: none;
	  border-radius: 50px;
	  position: relative;
	  overflow: hidden;
	  transition: 0.8s;
	  cursor: pointer;
	}

	.liquid-btn-1:hover {
	  background: #1565c0;
	  box-shadow: 0 0 20px rgba(33,150,243,0.5);
	}

	.liquid-btn-1::before {
	  content: '';
	  position: absolute;
	  top: 0;
	  left: -100%;
	  width: 100%;
	  height: 100%;
	  background: linear-gradient(
		90deg,
		transparent,
		rgba(255,255,255,0.4),
		transparent
	  );
	  transition: 0.8s;
	}

	.liquid-btn-1:hover::before {
	  left: 100%;
	}
    </style>
</head>
<body>
    <div class="liquid-button">
	<button class="liquid-btn-1">Hover Me</button>
    </div>
</body>
</html>

进阶版(动态边框)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CSS Liquid Button</title>
    <style>
	.liquid-btn-3 {
	  padding: 18px 36px;
	  font-size: 1.3rem;
	  background: linear-gradient(90deg, #4caf50, #8bc34a, #4caf50);
	  background-size: 200%;
	  color: white;
	  border: 2px solid transparent;
	  border-radius: 8px;
	  position: relative;
	  transition: 0.5s;
	  animation: bgFlow 3s linear infinite;
	}

	.liquid-btn-3::before {
	  content: '';
	  position: absolute;
	  top: -2px;
	  left: -2px;
	  right: -2px;
	  bottom: -2px;
	  background: linear-gradient(90deg, 
		#4caf50, #fff, #8bc34a, #fff, #4caf50);
	  background-size: 400%;
	  z-index: -1;
	  border-radius: 8px;
	  animation: borderFlow 4s linear infinite;
	}

	@keyframes bgFlow {
	  0% { background-position: 0% }
	  100% { background-position: 200% }
	}

	@keyframes borderFlow {
	  0% { background-position: 0% }
	  100% { background-position: 400% }
	}
    </style>
</head>
<body>
    <div class="liquid-button">
		<button class="liquid-btn-3">动态边框液体按钮</button>
    </div>
</body>
</html>

效果图

在这里插入图片描述

相关文章:

  • Hoppscotch 开源API 开发工具
  • 每日一题--进程与协程的区别
  • 第58天:Web攻防-SQL注入二次攻击堆叠执行SQLMAPTamper编写指纹修改分析调试
  • LCR 159. 库存管理 III
  • K8S学习之基础三十四:K8S之监控Prometheus部署pod版
  • AWTK-WEB 快速入门(5) - C 语言 WebSocket 应用程序
  • VSCODE 报错Fatal error: can‘t create CMakeFiles/hello_world.elf.dir/C_/Users/...
  • 通过turfjs使用线段分割矢量多边形
  • 【TPAMI 2024】卷积调制空间自注意力SpatialAtt,轻量高效,即插即用!
  • JVM常用概念之安全点轮询
  • TensorRT:高性能深度学习推理的利器
  • DeepSeek私有化部署与安装浏览器插件内网穿透远程访问实战
  • 轨道交通3U机箱CPCI电机控制板(DSP),主要运行控制算法以对牵引电机进行精准的运动控制
  • 【Go语言圣经5.1】
  • 微前端 无界wujie
  • 蓝牙技术联盟中国实体成立!华为、小米发声支持本土化战略
  • QAI AppBuilder 快速上手(7):目标检测应用实例
  • CVPR2025自动驾驶端到端前沿论文汇总
  • Docker命令解析:加速你的容器化之旅(以Nginx为例)
  • 设计模式Python版 访问者模式
  • 一周文化讲座|“我的生命不过是温柔的疯狂”
  • 商务部回应美方加严限制中国芯片:敦促美方立即纠正错误做法
  • 中日东三省问题的源起——《1905年东三省事宜谈判笔记》解题
  • 京东一季度净利增长五成,营收增速创近三年新高,称外卖业务取得显著进展
  • 何谓“战略稳定”:“长和平”的实现基础与机制
  • 不到1小时就能速发证件?央媒曝光健康证办理乱象