CSS彩色发光液体玻璃

效果展示

CSS 知识点

  • animation 综合运用
  • animation-delay 综合运用
  • filter 的 hue-rotate 属性运用

页面整体布局

html 复制代码
<section>
  <div class="glass" style="--i: 1">
    <div class="inner">
      <div class="liquid"></div>
    </div>
  </div>

  <div class="glass" style="--i: 2">
    <div class="inner">
      <div class="liquid"></div>
    </div>
  </div>

  <div class="glass" style="--i: 3">
    <div class="inner">
      <div class="liquid"></div>
    </div>
  </div>
</section>

核心样式

编写瓶子样式

css 复制代码
.glass {
  position: relative;
}

.glass .inner {
  position: relative;
  width: 200px;
  height: 400px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 40px;
  border: 8px solid transparent;
}

.glass .inner::before {
  content: "";
  position: absolute;
  width: calc(100% - 10px);
  height: 30px;
  border: 10px solid #444;
  border-radius: 50%;
  top: -15px;
  left: 50%;
  transform: translateX(-50%);
  box-shadow: 0 15px 0 #222;
}

.glass .inner::after {
  content: "";
  position: absolute;
  width: 50px;
  height: 250px;
  top: 80px;
  left: 30px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

编写瓶子液体样式

css 复制代码
.glass .inner::before {
  content: "";
  position: absolute;
  width: calc(100% - 10px);
  height: 30px;
  border: 10px solid #444;
  border-radius: 50%;
  top: -15px;
  left: 50%;
  transform: translateX(-50%);
  box-shadow: 0 15px 0 #222;
}

.glass .inner::after {
  content: "";
  position: absolute;
  width: 50px;
  height: 250px;
  top: 80px;
  left: 30px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

.liquid {
  position: absolute;
  top: 50px;
  left: 5px;
  right: 5px;
  bottom: 1px;
  background: #41c1fb;
  border-bottom-left-radius: 30px;
  border-bottom-right-radius: 30px;
  filter: drop-shadow(0 0 80px #41c1fb);
}

.liquid::before {
  content: "";
  position: absolute;
  width: 100%;
  height: 20px;
  border-radius: 50%;
  background: #1fa4e0;
  top: -10px;
}

编写动画

css 复制代码
.glass .inner {
  animation: animateColor 5s linear infinite;
  animation-delay: calc(var(--i) * -1.25s);
}

@keyframes animateColor {
  0% {
    filter: hue-rotate(0deg);
  }
  100% {
    filter: hue-rotate(360deg);
  }
}

.liquid {
  animation: animateLiquid 5s linear infinite;
  animation-delay: calc(var(--i) * -1.25s);
}

@keyframes animateLiquid {
  0%,
  20% {
    top: 50px;
  }
  50%,
  70% {
    top: 320px;
  }
  100% {
    top: 50px;
  }
}

完整代码下载

完整代码下载

相关推荐
Smile_Gently1 小时前
前端:最简单封装nmp插件(组件)过程。
前端·javascript·vue.js·elementui·vue
luckycoke8 小时前
小程序立体轮播
前端·css·小程序
一 乐8 小时前
高校体育场管理系统系统|体育场管理系统小程序设计与实现(源码+数据库+文档)
前端·javascript·数据库·spring boot·高校体育馆系统
懒羊羊我小弟8 小时前
常用Webpack Loader汇总介绍
前端·webpack·node.js
祈澈菇凉8 小时前
ES6模块的异步加载是如何实现的?
前端·javascript·es6
我爱学习_zwj9 小时前
4.从零开始学会Vue--{{组件通信}}
前端·javascript·vue.js·笔记·前端框架
顾比魁9 小时前
XSS盲打:当攻击者“盲狙”管理员
前端·网络安全·xss
黑客老李9 小时前
新手小白如何挖掘cnvd通用漏洞之存储xss漏洞(利用xss钓鱼)
java·运维·服务器·前端·xss
晚风予星9 小时前
简记|LogicFlow自定义BPMN元素节点
前端
Json____9 小时前
使用html css js 开发一个 教育机构前端静态网站模板
前端·css·html·js·前端学习·企业站·教育机构网站