text-justify

可用性有限

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

text-justify CSS 属性用于设置当元素上设置了 text-align: justify; 时,文本应采用何种对齐方式。

语法

css
text-justify: none;
text-justify: auto;
text-justify: inter-word;
text-justify: inter-character;
text-justify: distribute; /* Deprecated value */

/* Global values */
text-justify: inherit;
text-justify: initial;
text-justify: revert;
text-justify: revert-layer;
text-justify: unset;

none

文本对齐功能已关闭。这与完全不设置 text-align 具有相同的效果,尽管如果您出于某种原因需要打开和关闭对齐功能,这会很有用。

auto

浏览器根据性能和质量之间的平衡,以及文本语言(例如,英语、CJK 语言等)最适合的方式,选择当前情况的最佳对齐方式。这是在未设置 text-justify 时使用的默认对齐方式。

单词间

通过在单词之间添加空格(有效地改变 word-spacing)来对齐文本,这最适用于使用空格分隔单词的语言,例如英语或韩语。

字符间

通过在字符之间添加空格(有效地改变 letter-spacing)来对齐文本,这最适用于日语等语言。

分配

inter-character 表现相同;此值是为了向后兼容而保留的。

正式定义

初始值auto
应用于行内级和表格单元格元素
继承性
计算值同指定值
动画类型离散

正式语法

text-justify = 
[ auto | none | inter-word | inter-character | ruby ] ||
no-compress

示例

text-justify 不同值的演示

css
p {
  font-size: 1.5em;
  border: 1px solid black;
  padding: 10px;
  width: 95%;
  margin: 10px auto;
  text-align: justify;
}

.none {
  text-justify: none;
}

.auto {
  text-justify: auto;
}

.dist {
  text-justify: distribute;
}

.word {
  text-justify: inter-word;
}

.char {
  text-justify: inter-character;
}

规范

规范
CSS Text Module Level 3
# text-justify 属性

浏览器兼容性

另见