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

完整代码下载

完整代码下载

相关推荐
counterxing2 小时前
我整理了一个免费开发资源目录,还做成了 CLI 和 MCP
前端·agent·ai编程
子兮曰9 小时前
Bun v1.3.14 深度解析:Image API、HTTP/3、全局虚拟存储与五十项变革
前端·后端·bun
kyriewen10 小时前
今天,百年巨头一次砍了9200人,而一个离职科学家的实话让全网睡不着觉
前端·openai·ai编程
问心无愧051310 小时前
ctf show web 入门42
android·前端·android studio
kyriewen11 小时前
老板逼我上AI,我偷偷在浏览器里跑LLaMA,省下20万API费
前端·react.js·llm
Beginner x_u11 小时前
前端八股整理(手写 02)|数组转树、数组扁平化、随机打乱一个数组
前端·数组·数组转树·数组扁平化
KaMeidebaby11 小时前
卡梅德生物技术快报|禽类成纤维细胞 FISH 实验:鸟类性别染色体基因定位技术实现与数据验证
前端·数据库·其他·百度·新浪微博
天若有情67311 小时前
前端高阶性能优化:跳出传统懒加载与预加载,基于用户行为做轻量预判加载
前端·性能优化
小小小小宇11 小时前
前端转后端:SQL 是什么
前端
张元清12 小时前
React Observer Hooks:7 种监听 DOM 而不写样板代码的方式
前端·javascript·面试