MDN wants to talk to developers like you: https://qsurvey.mozilla.com/s3/a3e7b5301fea

概述

text-indent 属性 规定了 一个元素 首行 文本内容之前应该有多少水平空格。Horizontal spacing is with respect to the left (or right, for right-to-left layout) edge of the containing block element's box.

初始值0
适用元素block containers
是否是继承属性yes
Percentagesrefer to the width of the containing block
适用媒体visual
计算值the percentage as specified or the absolute length, plus any keywords as specified
Animation typea length, percentage or calc();
正规顺序The length or percentage before the keywords, if both are present. If several keywords are present, they appear in the same order as their appearance in the formal grammar.

Syntax

Formal syntax: <length-percentage> && hanging? && each-line?

where
<length-percentage> = <length> | <percentage>

text-indent: 3em       /*  values */
text-indent: 40px
text-indent: 15%       /*  values, relatives to the containing block width */
text-indent: each-line /* keywords values */
text-indent: hanging

text-indent: inherit

Values

<length>
使用固定的<length>值来指定文本的缩进。允许使用负值。查阅可能<length> 单位。
Indentation is specified as fixed <length>. Negative values are allowed. See <length> values for possible units.
<percentage>
Indentation is a <percentage> of the containing block width.
each-line
文本缩进会影响第一行,以及使用<br>强制断行后的第一行。
hanging
该值会对所有的行进行反转缩进:除了第一行之外的所有的行都会被缩进,看起来就像第一行设置了一个负的缩进值。

Examples

p { text-indent: 2em } 

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.

Specifications

Specification Status Comment
CSS Text Module Level 3
text-indent
Working Draft Added the hanging and each-line keywords
CSS Transitions
text-indent
Working Draft Lists text-indent as animatable.
CSS Level 2 (Revision 1)
text-indent
Recommendation The behavior with display: inline-block and anonymous block boxes have been explicitly defined.
CSS Level 1
text-indent
Recommendation  

Browser compatibility

Feature Firefox (Gecko) Chrome Internet Explorer Opera Safari
Basic support 1.0 (1.7 or earlier) 1.0 3.0 3.5 1.0 (85)
hanging 未实现 未实现 未实现 未实现 未实现
each-line 未实现 未实现 未实现 未实现 未实现
Feature Firefox Mobile (Gecko) Android IE Phone Opera Mobile Safari Mobile
Basic support 1.0 (1.9.2) ? ? ? ?
hanging 未实现 未实现 未实现 未实现 未实现
each-line 未实现 未实现 未实现 未实现 未实现

文档标签和贡献者

 此页面的贡献者: liyuhang1997, Sebastianz, fscholz, shuaiyunzhang, teoli, sunorry
 最后编辑者: liyuhang1997,