【css3】特效光柱

效果图:

代码:

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>光柱</title>
  <style>
    :root {
      /* 柱形上部分颜色 */
      --bar-shape: rgba(186, 210, 226, 0.9);
      /* 柱形顶部六边形颜色 */
      --bar-top: rgb(186, 210, 226);
      /* 柱形下部分颜色+柱形底部六边形 */
      --bar-bg: #f083b6;
      /* 柱形线条颜色 */
      --bar-line: rgba(0, 0, 0, 0.2);
      /* clip-path裁剪六边形 */
      --path: polygon(75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%, 25% 0);
      /* 柱形宽度-全局 */
      --w: 45px;
      /* 柱形高度最大值 */
      --h: 300px;
    }

    section {
      /* flex布局 */
      display: flex;
      align-items: flex-end;
      height: var(--h);
    }

    .bar {
      position: relative;
      width: var(--w);
      height: var(--height);
      margin-right: 20px;
      background: linear-gradient(to top, var(--bar-bg), var(--bar-shape));
      transition: all 1s;
    }

    .bar:hover {
      height: 100%;
    }

    .bar:last-child {
      margin-right: 0;
    }

    /* bar添加前后伪元素,设置为clip-path裁剪后的六边形 */
    .bar::before,
    .bar::after {
      content: "";
      position: absolute;
      width: var(--w);
      height: calc(var(--w) / 2.5);
      clip-path: var(--path);
      left: 0;
    }

    .bar::before {
      background: var(--bar-top);
      top: 0;
      /* 层级置于最上层 */
      z-index: 2;
      transform: translateY(-50%);
    }

    .bar::after {
      background: var(--bar-bg);
      bottom: 0;
      /* 层级置于最下层 */
      z-index: -1;
      transform: translateY(50%);
    }

    .bar span {
      position: absolute;
      --d: calc(var(--w) / 2);
      --b: calc(var(--w) / -2.5 / 2);
      width: var(--d);
      height: 101%;
      left: calc(50% - var(--d) / 2);
      bottom: var(--b);
      box-shadow: 0px -5px 5px var(--bar-line);
    }
  </style>
</head>

<body>
  <section>
    <div class="bar" style="--height: 5%; --w: 25px">
      <span></span>
    </div>
    <div class="bar" style="--height: 60%">
      <span></span>
    </div>
    <div class="bar" style="--height: 30%; --w: 50px">
      <span></span>
    </div>
    <div class="bar" style="--height: 60%; --w: 60px">
      <span></span>
    </div>
    <div class="bar" style="--height: 30%; --w: 30px">
      <span></span>
    </div>
    <div class="bar" style="--height: 80%; --w: 35px">
      <span></span>
    </div>
    <div class="bar" style="--height: 10%; --w: 45px">
      <span></span>
    </div>
  </section>
</body>

</html>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一只前端小博客

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值