CodePen(1)-边框炫彩和模糊炫彩特效
416 字
2 分钟
CodePen(1)-边框炫彩和模糊炫彩特效
边框炫彩和模糊炫彩特效
每日的css特效学习,今天z-index的炫彩边框

设计思路-html
- .place用于容器居中
- .outer用于提供炫彩变量
- .outer::after作为模糊炫彩层其z-index<1>1>
- .inner作为输入框其z-index<3>3>
- .border作为渲染边框z-index<2>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学习
-
首先利用houdini定义一个可用于animation的变量
@property --rotation {syntax: "<angle>";inherits: false;initial-value: 0deg;} -
然后外层容器实现居中效果
.place {margin: auto;display: flex;align-items: center;justify-content: center;padding: 200px;} -
里面输入框作为index<3把炫彩和模糊炫彩都挡住>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);}} -
使用一个.border div元素作为背景炫彩
.border {position: absolute;/* 向外扩展4px,刚好将outer的边框覆盖 */inset: calc(var(--border-size) * -1);border-radius: inherit;overflow: hidden;background: var(--gradient);z-index: 2;} -
模糊炫彩使用.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;}}
分享给其他人
如果该文章对您有帮助,欢迎分享给其他人阅读!
复制链接
相关文章
推荐筛选
1
Markdown 扩展功能
文章示例 了解 Firefly 中的 Markdown 功能
2
Markdown 教程 - 语法查看
文章示例 一个简明的 Markdown 博客示例。
3
Markdown Mermaid 图表
文章示例 一个包含 Mermaid 的 Markdown 博客文章简单示例。
4
KaTeX 数学公式示例
文章示例 展示 Firefly 主题对 KaTeX 数学公式的支持,包括行内公式、块级公式和复杂数学符号。
5
测试katex
测试内容 2025-12-12
随机文章
随机推荐