Home  >  Article  >  Web Front-end  >  How to set the first line indentation by 2 characters in css

How to set the first line indentation by 2 characters in css

王林
王林Original
2020-11-17 11:55:3010576browse

How to set the first line indentation by 2 characters in css: You can use the text-indent attribute to set the first line indentation by 2 characters, such as [text-indent:2em;]. The text-index attribute is used to specify the indentation of the first line of text in the text block, and em is a relative unit.

How to set the first line indentation by 2 characters in css

Related properties:

The text-indent property specifies the indentation of the first line of text in the text block.

(Video tutorial recommendation: css video tutorial)

Attribute value:

  • length defines a fixed indent. Default value: 0.

  • % Defines the indent based on a percentage of the width of the parent element.

  • #inherit Specifies that the value of the text-indent attribute should be inherited from the parent element.

Implementation code:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>首行缩进</title>
		<style>
			.demo{
				width: 550px;
				height: 200px;
				margin: 50px auto;
			}
			p{
				text-indent:2em;/*em是相对单位,2em即现在一个字大小的两倍*/
			}
			}
		</style>
	</head>
	<body>
		<div class="demo">
		<p>
		这是一段测试代码,是关于css文本缩进的一段文字。这是一段测试代码,是关于css文本缩进的一段文字。
		这是一段测试代码,是关于css文本缩进的一段文字。这是一段测试代码,是关于css文本缩进的一段文字。
		这是一段测试代码,是关于css文本缩进的一段文字。这是一段测试代码,是关于css文本缩进的一段文字。
		</p>
		</div>
	</body>
</html>

Related recommendations: CSS tutorial

The above is the detailed content of How to set the first line indentation by 2 characters in css. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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