Detailed explanation of the usage of text-indent in css and the difference between it and padding

零下一度
Release: 2017-06-19 14:46:55
Original
2356 people have browsed it

Syntax:
text-indent: length

Parameters:

length: Percentage number | A length value composed of a floating point number and a unit identifier , negative values are allowed. See Length Units

Description:

Retrieves or sets the indentation of the text in the object.
This attribute cannot be applied within an object that is disconnected by another object (such as).
The corresponding script feature is textIndent. Please see other books I have written.

Example:

div { text-indent : -5px; } div { text-indent : underline 10%; }
Copy after login

How to use text-indent in css
text-indent
indicates the indentation of the first line of text, such as in word The first line of indentation
For example: you want the first line of a text to be indented by 2 Chinese characters. The font size of this text is 12px.
Put it in
Here is your text
The definition is as follows
p{text-indent:25px;}

What is the difference between text-indent and padding in css?

text-indent does not affect the final width of the element, but there are compatibility issues. Padding affects the final width in lower versions of IE, the mainstream browser, but not in chrome and firefox. Affects the width, but the problem of inconsistent display in multiple browsers can be solved through CSS reset, so that they all affect the width in the end.
The basic difference between text-indent and padding:
1. Padding is based onbox model, applicable to inline and block level elements
2. Text-indent is based on inline typesetting, only applicable For elements at the block level, the first line of text
padding will be applied to the left padding area of the inline box or block box, which will affect the content-box, and the text sub-nodes will appear in inside the content-box, so all text will be shifted left.
As an inline-block level label, it is displayed in a fixed single line (and it is different from the white-space mechanism). The above difference does not exist.
So what’s the difference:
1. Text-indent is based on inline typesetting, which results in the application ofdirection: After rtl, the indent provided by text-indent appears on the right;padding -leftis not affected by direction.
Of course, the direction attribute is not commonly used for
2. The padding-left is based on the box model, so the box-sizing attribute will affect the element together with the padding-left and width attributes. The final width; text-indent will never affect the width of the element.
This is very important because the default style sheets of webkit and firefox will set the box-sizing: border-box of the input element. If you set width and padding-left at the same time, webkit/firefox and IE lower versions will appear. A big difference in width.
Therefore, when using padding-left, you need to reset the corresponding styles of webkit and firefox:


The above is the detailed content of Detailed explanation of the usage of text-indent in css and the difference between it and padding. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!