CodePen(1)-边框炫彩和模糊炫彩特效

416 字
2 分钟
CodePen(1)-边框炫彩和模糊炫彩特效

边框炫彩和模糊炫彩特效#

每日的css特效学习,今天z-index的炫彩边框

texiao1
texiao1

设计思路-html#

  • .place用于容器居中
  • .outer用于提供炫彩变量
  • .outer::after作为模糊炫彩层其z-index<1>
  • .inner作为输入框其z-index<3>
  • .border作为渲染边框z-index<2>
<div class="place">
<div class="outer">
<div class="inner">
<input name="in" type="text" placeholder="询问YI AI" />
</div>
<div class="border"></div>
</div>
</div>

css学习#

  1. 首先利用houdini定义一个可用于animation的变量

    @property --rotation {
    syntax: "<angle>";
    inherits: false;
    initial-value: 0deg;
    }
  2. 然后外层容器实现居中效果

    .place {
    margin: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 200px;
    }
  3. 里面输入框作为index<3把炫彩和模糊炫彩都挡住>

    .inner {
    background: light-dark(white, #1a1c1e);
    color: light-dark(#222, hsl(210, 8%, 66%));
    display: inline;
    padding: 1rem 0.5rem;
    position: relative;
    z-index: 3; /* 这里最顶层,挡住炫彩 */
    border-radius: inherit;
    display: grid;
    grid-template-columns: 400px; /* 提供高度撑开.outer父容器 */
    align-items: center;
    gap: 1rem;
    font-family: system-ui;
    }
    input {
    color: light-dark(#222, hsl(210, 8%, 66%));
    background: none;
    border: none;
    }
    input {
    font-size: 1rem;
    font-family: system-ui;
    font-weight: 300;
    &:focus {
    outline: none;
    }
    &:not(:placeholder-shown) {
    color: light-dark(black, white);
    }
    }
  4. 使用一个.border div元素作为背景炫彩

    .border {
    position: absolute;
    /* 向外扩展4px,刚好将outer的边框覆盖 */
    inset: calc(var(--border-size) * -1);
    border-radius: inherit;
    overflow: hidden;
    background: var(--gradient);
    z-index: 2;
    }
  5. 模糊炫彩使用.outer::after

    .outer {
    /* 声明边框大小,统一变量 */
    --border-size: 4px;
    /* 自定义houdini变量,实现旋转炫彩 */
    --gradient: conic-gradient(
    from var(--rotation) at 52% 49% in oklab,
    oklch(0.63 0.2 251.22) 27%,
    oklch(0.67 0.21 25.81) 33%,
    oklch(0.9 0.19 93.93) 41%,
    oklch(0.79 0.25 150.49) 49%,
    oklch(0.63 0.2 251.22) 65%,
    oklch(0.72 0.21 150.89) 93%,
    oklch(0.63 0.2 251.22)
    );
    animation: rotate 5s infinite linear;
    /* 声明外边框圆角 */
    border-radius: 4rem;
    background: none;
    position: relative;
    padding: 0;
    &::after {
    content: "";
    position: absolute;
    inset: -4px; /* 大幅向外扩张,突破父级限制 */
    background: var(--gradient);
    filter: blur(15px); /* 强力模糊,对抗圆角吞噬 */
    z-index: 1;
    border-radius: inherit;
    }
    }
分享给其他人
如果该文章对您有帮助,欢迎分享给其他人阅读!
复制链接

评论区

图片
犟哟
Hello, I'm Juyial.
公告
欢迎来到我的博客,在这里可以一起进步,一起学习!2026年起航!
站点统计
文章
23
分类
7
标签
13
总字数
14,269
运行时长
0
最后活动
0 天前

目录