700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 使用CSS实现首行缩进效果

使用CSS实现首行缩进效果

时间:2024-02-14 05:54:04

相关推荐

使用CSS实现首行缩进效果

在CSS中,可以使用text-indent属性来实现首行缩进效果。text-indent属性用于定义每个文本块中第一行的缩进;它可采取负值。如果使用负值,那么首行会被缩进到左边。下面本篇文章就来给大家介绍一下text-indent属性,希望对大家有所帮助。

CSS text-indent属性

text-indent属性规定文本块中首行文本的缩进。该属性用于定义块级元素中第一个内容行的缩进。这最常用于建立一个“标签页”效果。允许指定负值,这会产生一种“悬挂缩进”的效果。

语法:

text-indent: length|initial|inherit;

属性值:

●length:用于根据px,pt,cm,em等设置固定缩进;长度的默认值为0。

text-indent: length;

●百分比(%):用于定义与元素宽度相比的缩进百分比。

text-indent: %;

●initial:用于将text-indent属性设置为其默认值。

text-indent: initial;

示例:

<!DOCTYPE html><html><head><meta charset="utf-8"><title> CSS text-indent属性</title> <!-- CSS text-indent属性 --><style> .box{padding:0px 60px 0px;}.demo1 { text-indent: 70px; } .demo2 { text-indent: -3em; } .demo3 { text-indent: 40%; } </style> </head> <body> <h2> text-indent属性</h2> <div class="box"><h2>text-indent: 70px:</h2> <div class = "demo1">这是一段测试代码,是关于css文本缩进的一段文字。这是一段测试代码,是关于css文本缩进的一段文字。这是一段测试代码,是关于css文本缩进的一段文字。这是一段测试代码,是关于css文本缩进的一段文字。这是一段测试代码,是关于css文本缩进的一段文字。这是一段测试代码,是关于css文本缩进的一段文字。 </div> <h2>text-indent: -3em:</h2> <div class = "demo2">这是一段测试代码,是关于css文本缩进的一段文字。这是一段测试代码,是关于css文本缩进的一段文字。这是一段测试代码,是关于css文本缩进的一段文字。这是一段测试代码,是关于css文本缩进的一段文字。这是一段测试代码,是关于css文本缩进的一段文字。这是一段测试代码,是关于css文本缩进的一段文字。</div> <h2>text-indent: 40%:</h2> <div class = "demo3">这是一段测试代码,是关于css文本缩进的一段文字。这是一段测试代码,是关于css文本缩进的一段文字。这是一段测试代码,是关于css文本缩进的一段文字。这是一段测试代码,是关于css文本缩进的一段文字。这是一段测试代码,是关于css文本缩进的一段文字。这是一段测试代码,是关于css文本缩进的一段文字。</div></div></body> </html>

效果图:

浏览器支持

CSS text-indent属性支持的浏览器如下所示:

●Google Chrome 1.0

●Internet Explorer 3.0

●Firefox 1.0

●Safari 1.0

●Opera 3.5

本文参考地址:/qa/css3/10363.html

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。