text-emphasis纯CSS属性,HTML中设attribute无效;须用style或CSS规则,且-webkit版必须前置、值顺序为“style color”、中文仅支持under位置。

直接用 text-emphasis 基本无效,尤其在 iOS Safari 上——必须配 -webkit-text-emphasis 且位置设为 under,否则点不显示、位置飘、或静默失败。
为什么写 text-emphasis="dot red" 在 HTML 标签里完全没反应
浏览器根本不识别这个 attribute —— text-emphasis 是纯 CSS 属性,和 color 一样,只在样式作用域生效。写成 <p text-emphasis="dot red">文字</p> 后,开发者工具里查不到任何 computed text-emphasis 值,它被直接忽略,零报错、零提示。
- 正确路径只有两种:内联
style或 CSS 规则 - 内联示例:
style="-webkit-text-emphasis: dot #e74c3c; text-emphasis: dot #e74c3c; -webkit-text-emphasis-position: under; text-emphasis-position: under;" - 类名写法更推荐:
.emph { -webkit-text-emphasis: dot #e74c3c; text-emphasis: dot #e74c3c; -webkit-text-emphasis-position: under; text-emphasis-position: under; }
必须成对声明 -webkit-text-emphasis 和 text-emphasis,且顺序不能反
Safari(尤其是 iOS)只认 -webkit- 版本;Chrome/Firefox/Edge 虽支持无前缀版,但若你把标准版写在前、前缀版写在后,WebKit 引擎可能用标准值覆盖前缀值,导致 iOS 上回归空白。
- 安全写法:前缀版必须在前,标准版紧随其后
- 值顺序敏感:
dot必须在颜色前,red dot会被解析失败 - 拆开写
text-emphasis-style+text-emphasis-color不稳定,旧版 Safari 可能只生效一个
中文必须用 text-emphasis-position: under,over 基本不可用
over 是为拉丁字母设计的,按英文字母基线定位;汉字字身高、视觉重心上移,结果就是圆点悬在字顶上,常被截断或与上一行重叠。实测多数中文字体(如 PingFang SC、Microsoft YaHei)在 over 下仍不稳定。
立即学习“前端免费学习笔记(深入)”;
-
under是中文唯一可用的底线位置,但必须成对声明:-webkit-text-emphasis-position: under+text-emphasis-position: under - 别指望靠调
line-height挽救over—— 它解决不了基线逻辑错位问题 - 如果内容含英文、数字或空格(比如表格单元格),
text-emphasis渲染成功率极低,建议直接换color+background-color
真正麻烦的不是写法,而是字体依赖和渲染时机:强调符大小是文字字号的一半,且与字体基线强耦合;同一段文字在不同系统字体下,点的位置、是否重叠、甚至是否出现,都可能不一致。上线前务必在真机(特别是 iPhone)上逐字检查。


















