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;
  }
}

完整代码下载

完整代码下载

相关推荐
昨天;明天。今天。几秒前
案例-任务清单
前端·javascript·css
zqx_71 小时前
随记 前端框架React的初步认识
前端·react.js·前端框架
惜.己1 小时前
javaScript基础(8个案例+代码+效果图)
开发语言·前端·javascript·vscode·css3·html5
什么鬼昵称2 小时前
Pikachu-csrf-CSRF(get)
前端·csrf
长天一色2 小时前
【ECMAScript 从入门到进阶教程】第三部分:高级主题(高级函数与范式,元编程,正则表达式,性能优化)
服务器·开发语言·前端·javascript·性能优化·ecmascript
NiNg_1_2342 小时前
npm、yarn、pnpm之间的区别
前端·npm·node.js
秋殇与星河2 小时前
CSS总结
前端·css
BigYe程普3 小时前
我开发了一个出海全栈SaaS工具,还写了一套全栈开发教程
开发语言·前端·chrome·chatgpt·reactjs·个人开发
神之王楠3 小时前
如何通过js加载css和html
javascript·css·html
余生H3 小时前
前端的全栈混合之路Meteor篇:关于前后端分离及与各框架的对比
前端·javascript·node.js·全栈