css设置首行缩进2个字符的方法:可以利用text-indent属性来设置首行缩进2个字符,如【text-indent:2em;】。text-index属性用于规定文本块中首行文本的缩进,em是相对单位。

相关属性: text-indent 属性规定文本块中首行文本的缩进。 (视频教程推荐:css视频教程) 属性值: 实现代码: <!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>相关推荐:CSS教程 以上就是css如何设置首行缩进2个字符的详细内容,更多请关注模板之家(www.mb5.com.cn)其它相关文章! |