Thanks to visit codestin.com
Credit goes to github.com

Skip to content

有趣的 ::first-letter #8

@yisibl

Description

@yisibl

🙈本文正在施工中,请保持关注。🙈

Unicode 中将字符分为了七大类,其中大写的 P 表示标点符号,具体的分类如下:

类别 表示

C

(所有控制字符)CcCfCsCo 和 Cn

L

(所有字母)LuLlLtLm 和 Lo

M

(所有附加符号标记)MnMc 和 Me

N

(所有数字)NdNl 和 No

P

(所有标点)PcPdPsPePiPf 和 Po

S

(所有符号)SmScSk 和 So

Z

(所有分隔符)ZsZl 和 Zp

然后每个大的分类下面进一步细分,本文涉及到的标点符号具体的含义如下:

类别 英文全称 含义 CSS 版本
Pc ConnectorPunctuation 指示字符是连接两个字符的连接符标点。 CSS Pseudo-Elements 4
Pd DashPunctuation 指示字符是短划线或连字符。 CSS Pseudo-Elements 4
Ps OpenPunctuation 指示字符是成对的标点符号(例如括号、方括号和大括号)之一的开始字符。 CSS 2
Pe ClosePunctuation 指示字符是成对的标点符号(例如括号、方括号和大括号)之一的封闭字符。 CSS 2
Pi InitialQuotePunctuation 指示字符是开始或前引号。 CSS 2
Pf FinalQuotePunctuation 指示字符是封闭或后引号。 CSS 2
Po OtherPunctuation 指示字符是标点,但它不是连接符标点、短划线标点、开始标点、结束标点、前引号标点或后引号标点。 CSS 2

Firefox 48 之前,::first-letter 仅支持 CSS 2 中规定的 "open" (Ps), "close" (Pe), "initial" (Pi). "final" (Pf) and "other" (Po) 标点。

Punctuation (i.e, characters defined in Unicode [UNICODE] in the "open" (Ps), "close" (Pe), "initial" (Pi). "final" (Pf) and "other" (Po) punctuation classes), that precedes or follows the first letter should be included, as in:

CSS Pseudo-Elements 4 中做了些许修改,所有的标点符号全部包含在内:

Punctuation (i.e, characters that belong to the Punctuation (P*) Unicode general category [UAX44]) that precedes or follows the first typographic letter unit must also be included in the ::first-letter pseudo-element.

所以 Firefox 48 之前并不支持 Pc(例如 ) 和 Pd(例如 -_)中的字符,这里修复了这个问题。其他浏览器的支持也不正确,::first-letter 应该选中第一个标点符号以及第一个字符。
(截图来自 MDN 文档
Firefox 47
Chrome 50

符合规范的效果应该是这样的:

Firefox 48

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions