--- title: text-justify slug: Web/CSS/text-justify tags: - CSS文字 - 布局 - 排版 translation_of: Web/CSS/text-justify ---
CSS属性 text-justify
定义的是当文本的 {{cssxref("text-align")}} 属性被设置为 :justify
时的齐行方法。
text-justify: none; text-justify: auto; text-justify: inter-word; text-justify: inter-character; text-justify: distribute; /* 已被废除,不提倡使用 */
{{cssinfo}}
text-justify
属性的值只能取下面列表中的单个关键词值。
none
none
属性时,的确可以禁用掉齐行设置,但是谷歌下还是没有设置 none
属性时的效果。auto
text-justify
进行设置的话,则是默认使用这样子的对齐规则。inter-word
inter-character
distribute
{{deprecated_inline}}inter-word
一致,不提倡使用这个属性,现在这个属性或许还能有效果,但那完全是为了向后兼容而被保留着。<p class="none"><code>text-justify: none</code> —<br>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc ornare maximus vehicula. Duis nisi velit, dictum id mauris vitae, lobortis pretium quam. Quisque sed nisi pulvinar, consequat justo id, feugiat leo. Cras eu elementum dui.</p> <p class="auto"><code>text-justify: auto</code> —<br>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc ornare maximus vehicula. Duis nisi velit, dictum id mauris vitae, lobortis pretium quam. Quisque sed nisi pulvinar, consequat justo id, feugiat leo. Cras eu elementum dui.</p> <p class="dist"><code>text-justify: distribute</code> —<br>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc ornare maximus vehicula. Duis nisi velit, dictum id mauris vitae, lobortis pretium quam. Quisque sed nisi pulvinar, consequat justo id, feugiat leo. Cras eu elementum dui.</p> <p class="word"><code>text-justify: inter-word</code> —<br>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc ornare maximus vehicula. Duis nisi velit, dictum id mauris vitae, lobortis pretium quam. Quisque sed nisi pulvinar, consequat justo id, feugiat leo. Cras eu elementum dui.</p> <p class="char"><code>text-justify: inter-character</code> —<br>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc ornare maximus vehicula. Duis nisi velit, dictum id mauris vitae, lobortis pretium quam. Quisque sed nisi pulvinar, consequat justo id, feugiat leo. Cras eu elementum dui.</p>
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; }
{{EmbedLiveSample("示例","100%",400)}}
规范 | 状态 | 备注 |
---|---|---|
{{SpecName('CSS3 Text', '#text-justify-property', 'text-justify')}} | {{Spec2('CSS3 Text')}} |
{{CompatibilityTable}}
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | {{CompatNo}}[2] | 14[1] | {{CompatGeckoDesktop("55.0")}} | 11[1] | {{CompatNo}}[2] | {{CompatNo}} |
Feature | Android | Chrome for Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|---|
Basic support | {{CompatNo}}[2] | {{CompatNo}}[2] | 14[1] | {{CompatGeckoMobile("55.0")}} | 11[1] | {{CompatNo}}[2] | {{CompatNo}} |
[1] 不支持标准属性值 inter-character
或 none
。但是支持过时的属性值 distribute
和废弃属性值 distribute-all-lines
、distribute-center-last
、inter-cluster
、inter-ideograph
,以及 newspaper
。
[2] 参照了默认的规范,属性值 inter-word
和 distribute
在“实验平台特性”的旗帜下被保留了下来,尽管 distribulte
已经不被提倡使用了。