使用CSS实现首行缩进效果

3 篇文章 0 订阅

在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>

效果图:

1562383105104358.png

浏览器支持

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

● Google Chrome 1.0

● Internet Explorer 3.0

● Firefox 1.0

● Safari 1.0

● Opera 3.5


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

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值