悬挂标点

**hanging-punctuation** CSS 属性指定标点符号是否应悬挂在文本行首或行尾。悬挂标点符号可以放置在行框之外。

语法

css
/* Keyword values */
hanging-punctuation: none;
hanging-punctuation: first;
hanging-punctuation: last;
hanging-punctuation: allow-end;

/* Two keywords */
hanging-punctuation: first allow-end;
hanging-punctuation: first last;
hanging-punctuation: last allow-end;

/* Three keywords */
hanging-punctuation: first allow-end last;

/* Global values */
hanging-punctuation: inherit;
hanging-punctuation: initial;
hanging-punctuation: revert;
hanging-punctuation: revert-layer;
hanging-punctuation: unset;

hanging-punctuation 属性可以用一个、两个或三个用空格分隔的值指定。

none

没有字符悬挂。

first

元素第一个格式化行的开头处的开括号或引号悬挂。这适用于

  • Unicode 类别 PsPfPi 中的所有字符
  • 引号标记 U+0027 APOSTROPHE (') 和 U+0022 QUOTATION MARK (")。
last

元素最后一个格式化行的结尾处的闭括号或引号悬挂。这适用于

  • Unicode 类别 PePfPi 中的所有字符
  • 引号标记 U+0027 APOSTROPHE (') 和 U+0022 QUOTATION MARK (")。
allow-end

如果句号或逗号在行尾不适合在对齐之前,则将其悬挂。

允许悬挂的句号和逗号包括

  • U+002C,COMMA
  • U+002E,FULL STOP
  • U+060C,ARABIC COMMA
  • U+06D4,ARABIC FULL STOP
  • U+3001,IDEOGRAPHIC COMMA
  • U+3002,IDEOGRAPHIC FULL STOP
  • U+FF0C,FULLWIDTH COMMA
  • U+FF0E,FULLWIDTH FULL STOP
  • U+FE50,SMALL COMMA
  • U+FE51,SMALL IDEOGRAPHIC COMMA
  • U+FE52,SMALL FULL STOP
  • U+FF61,HALFWIDTH IDEOGRAPHIC FULL STOP
  • U+FF64,HALFWIDTH IDEOGRAPHIC COMMA

用户代理可以包含其他字符。

正式定义

初始值none
应用于所有元素
继承
计算值按指定
动画类型离散

正式语法

hanging-punctuation = 
none |
[ first || [ force-end | allow-end ] || last ]

示例

将开头和结尾引号设置为悬挂

HTML

html
<p>
  «For a moment, nothing happened. Then, after a second or so, nothing continued
  to happen.»
</p>

<p class="hanging">
  «For a moment, nothing happened. Then, after a second or so, nothing continued
  to happen.»
</p>

<p class="hanging right">
  «For a moment, nothing happened. Then, after a second or so, nothing continued
  to happen.»
</p>

CSS

css
p {
  width: 15em;
  border: 1px solid #cccccc;
  font-size: 2rem;
  font-style: italic;
  margin: 1em;
}

p.hanging {
  hanging-punctuation: first last;
}

p.right {
  text-align: right;
}

结果

规范

规范
CSS 文本模块第 3 级
# hanging-punctuation-property

浏览器兼容性

BCD 表格仅在浏览器中加载

另请参阅