--- title: text-indent slug: Web/CSS/text-indent translation_of: Web/CSS/text-indent ---
text-indent
属性能定义一个块元素首行文本内容之前的缩进量。
/* <length> 长度值 */
text-indent: 3mm;
text-indent: 40px;
/* <percentage>百分比值取决于其包含块(containing block)的宽度*/
text-indent: 15%;
/* 关键字 */
text-indent: 5em each-line;
text-indent: 5em hanging;
text-indent: 5em hanging each-line;
/* 全局值 */
text-indent: inherit;
text-indent: initial;
text-indent: unset;
<length>
使用固定的<length>值来指定文本的缩进。允许使用负值。查阅可能
的 {{cssxref("<length>")}} 单位。<percentage>
each-line
{{experimental_inline}}hanging
{{experimental_inline}}<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy
nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
p {
text-indent: 5em;
background: powderblue;
}
{{EmbedLiveSample('例子')}}
Specification | Status | Comment |
---|---|---|
{{SpecName('CSS3 Text', '#text-indent', 'text-indent')}} | {{Spec2('CSS3 Text')}} | Added the hanging and each-line keywords |
{{SpecName('CSS3 Transitions', '#animatable-css', 'text-indent')}} | {{Spec2('CSS3 Transitions')}} | Lists text-indent as animatable. |
{{SpecName('CSS2.1', 'text.html#indentation-prop', 'text-indent')}} | {{Spec2('CSS2.1')}} | The behavior with display: inline-block and anonymous block boxes have been explicitly defined. |
{{SpecName('CSS1', '#text-indent', 'text-indent')}} | {{Spec2('CSS1')}} |
{{cssinfo}}
{{Compat("css.properties.text-indent")}}