SuperAPI AI 工具集

smooth-shadow-ring

前端与建站

查看项目

更新于 10-15 21:42

技能介绍

用途:在安装了 shadow-plugin 的 Tailwind 项目中,为任意浮于页面之上的表面(卡片、对话框、模态框、弹出层、下拉菜单、菜单、提示框、抽屉、Toast、命令面板等)提供统一的边缘样式。

要解决的问题:在同一元素上同时使用 border-(或 ring-)与 shadow-* 会画出两条叠加的边——边框是硬 1px 描边,阴影从边框外侧开始,形成明显的双边缘,显得厚重、发灰。

规则:在浮起表面上,若准备在 shadow-* 旁写 border-* 或 ring-,改用 smooth-shadow-ring-{size},它把 1px 发丝环烘焙进最终阴影层,使边缘与阴影连成一体。例如 border shadow-md 换成 smooth-shadow-ring-md;ring-1 ring-neutral-200 shadow-lg 换成 smooth-shadow-ring-lg。可用尺寸:smooth-shadow-ring-xs、-sm、-md(或裸写 smooth-shadow-ring)、-lg、-xl、-2xl。已经使用 smooth-shadow-ring- 的元素不要再保留 border 或 ring,否则会叠出第二道边。若表面不应有任何描边,用不带环的 smooth-shadow-{size},而不是 border。

着色:环与阴影可独立着色并在同一元素合成。shadow-{color} 给阴影染色(如 shadow-blue-500),smooth-ring-{color} 给环染色(如 smooth-ring-black/10、smooth-ring-blue-500/40)。环默认 rgba(0,0,0,0.05),在深色模式下变为 rgba(255,255,255,0.18),触发条件为 .dark 类、data-theme="dark",或页面声明 color-scheme: light dark 时的系统偏好深色;它不单独依赖 prefers-color-scheme,因此纯浅色站点对所有访客保持浅色环。若站点深色仅由 prefers-color-scheme 媒体查询驱动,需声明 :root { color-scheme: light dark; } 让环跟随。深色 alpha 更高是有意为之:环画在表面之外,其颜色来自背后页面而非所描边的表面。若表面本身颜色接近环色(深色页面上 neutral-700 及以上),请显式设置 smooth-ring-*。

环宽:默认 1px,并自动跟随项目的 Tailwind ring 宽度,例如 @theme { --default-ring-width: 0.5px; } 会得到 0.5px 发丝环,无需额外设置。不要硬编码宽度去匹配;仅当必须与项目环宽不同时,才在任意作用域覆盖 --smooth-ring-width,例如按元素写 [--smooth-ring-width:2px]。

覆盖:这些工具类不带 !important,遵循正常级联,后续工具类、内联样式或 JS 对 box-shadow 的动画均可正常覆盖。当需要压过更高级别的 CSS(如组件库自带、通常未分层的 box-shadow)时,在该元素上使用 Tailwind 的 important 修饰符,例如 class="smooth-shadow-ring-md!",而不要做全局覆盖。

限制:仅适用于已安装 shadow-plugin 的 Tailwind 项目。其余环境、版本兼容与安装方式资料暂未提供。