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 屬性

瀏覽器相容性

另見