你以为下划线只能靠 skip-ink 断升部?今天 Chrome 把装饰线两端也彻底原生化了

写过排版的人都踩过这个坑——下划线每次都穿过字母的升部(g、y、p),设计师说「要断开」,结果你调了半天 text-decoration-skip-ink: auto 还是不尽如人意。今天 Chrome 154 用一个属性把这件事彻底原生化了。

text-decoration-inset 做了什么

text-decoration-inset 是 CSS Text Decoration Level 4 里的新属性,控制装饰线(underline、overline、line-through)相对于文字边缘的内嵌距离。以前要靠手动 padding + 负 margin 绕一圈,现在一行搞定。

a {
  text-decoration: underline;
  text-decoration-inset: 0.15em;
}

0.15em 的意思是:装饰线从文字左右边缘各缩进 0.15em,不再像默认那样顶到头。对中文排版尤其有用——中文字符虽然没有升部,但如果你在混排内容里用同一套样式,这个属性能让装饰线视觉上更干净。

完整三件套:inset、skip、thickness

2026 年的 CSS Text Decoration 已经是三件套组合拳:

.card-title {
  text-decoration: underline;
  text-decoration-color: #6366f1;
  text-decoration-thickness: 2px;       /* 粗细 */
  text-decoration-skip-ink: auto;       /* 穿过升部时断开 */
  text-decoration-inset: 0.2em;         /* 装饰线两端内嵌 */
}
  • text-decoration-thickness — 控制装饰线宽度(Chrome 153+)
  • text-decoration-skip-ink — 控制穿过升部时的行为(已有,auto/all)
  • text-decoration-inset — 控制装饰线端点内嵌距离(Chrome 154+,Firefox 155+)

三行 CSS 替代了过去需要 SVG background-image 或复杂伪元素才能实现的效果。

实际场景

最典型的场景:设计系统里按钮链接的样式。你的按钮文字是 #1a1a2e 这样的深色,设计师要求下划线在每个字母两侧各留一点白,不贴边。text-decoration-inset: 0.15em 直接写死就行,不需要任何 hack。

另一个场景:卡片标题区的装饰线。设计稿里装饰线宽度只有 1px、距文字底部 3px、左右各缩进 0.2em,这三个参数在 CSS 里有对应的精确控制。

浏览器支持

Chrome 154+、Firefox 155+ 已稳定支持,Safari 暂未实现。Baseline 2026 Newly Available,实际生产使用建议加 @supports 回退:

.link {
  text-decoration: underline;
}
@supports (text-decoration-inset: 0.15em) {
  .link {
    text-decoration-inset: 0.15em;
  }
}

不支持的浏览器降级到默认装饰线行为,功能渐进增强,不影响可用性。

评论区

0 条评论

登录后可评论。

小鹿·界面实验室 320 阅读