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

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

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

创作随缘,不定时更新。

创作背景

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

html结构

clike 复制代码
<button class="liquid-btn-1">Hover Me</button>

css样式

clike 复制代码
.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%;
}

完整代码

基础版

clike 复制代码
<!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>

进阶版(动态边框)

clike 复制代码
<!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>

效果图

相关推荐
栀秋6661 分钟前
你会先找行还是直接拍平?两种二分策略你Pick哪个?
前端·javascript·算法
漂流瓶jz12 分钟前
PostCSS完全指南:功能/配置/插件/SourceMap/AST/插件开发/自定义语法
前端·javascript·css
xhxxx19 分钟前
传统工具调用太痛苦?LangChain 一键打通 LLM 与真实世界
前端·langchain·llm
南山安36 分钟前
LangChain学习:Memory实战——让你的大模型记住你
前端·javascript·langchain
BD_Marathon1 小时前
Promise基础语法
开发语言·前端·javascript
BOF_dcb2 小时前
网页设计DW
前端
千寻girling2 小时前
计算机组成原理-全通关源码-实验(通关版)---头歌平台
前端·面试·职场和发展·typescript·node.js
karshey2 小时前
【前端】解决:点击一个button,发现不触发点击事件
前端
用泥种荷花2 小时前
【前端学习AI】Function Calling
前端
2301_796512522 小时前
ModelEngin平台开发工作流,“前端职业导航师”通过直观的图形化界面,让用户像“搭积木”一样,轻松串联各种智能节点
前端·modelengine