hanging-punctuation

可用性有限

此特性不是基线特性,因为它在一些最广泛使用的浏览器中不起作用。

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,逗号
  • U+002E,句号
  • U+060C,阿拉伯逗号
  • U+06D4,阿拉伯句号
  • U+3001,表意逗号
  • U+3002,表意句号
  • U+FF0C,全角逗号
  • U+FF0E,全角句号
  • U+FE50,小逗号
  • U+FE51,小表意逗号
  • U+FE52,小句号
  • U+FF61,半角表意句号
  • U+FF64,半角表意逗号

用户代理可以包含额外的字符。

正式定义

初始值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 Text Module Level 3
# hanging-punctuation-property

浏览器兼容性

另见