CSS之伪元素

本文介绍了CSS伪元素:first-line、:first-letter、:before和:after的使用方法及可应用的属性,通过实例展示了如何对文本的首行和首字母进行样式设置,并在元素前后插入内容。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="zh-cn">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>CSS伪元素</title>
	<style type="text/css">
		/*:first-line伪元素 用于向文本的首行设置特殊样式
		*注意:first-line伪元素只能用于块级元素
		*可应用的属性
		*font
		*color
		*background
		*word-spacing
		*letter-spacing
		*text-decoration
		*vertical-align
		*text-transform
		*line-height
		*clear
		*/
		p:first-line{
			color:#ff0000;
			font-variant:small-caps;
		}
		/*:first-letter伪元素 用于向文本的首字母设置特殊样式,只能用于块级元素
		注释:下面的属性可应用于 "first-letter" 伪元素:
		*font
		*color
		*background
		*margin
		*padding
		*border
		*text-decoration
		*vertical-align (仅当 float 为 none 时)
		*text-transform
		*line-height
		*float
		*clear
		*/
		p:first-letter{
			color:#ff0000;
			font-size:xx-large;
		}
		/*:before伪元素 在元素的内容前面插入新内容*/
		h2:before{
			content:url(bibi.jpg);
		}
		/*:after伪元素 在元素的内容之后插入新内容*/
		h1:after{
			content:url(bibi.jpg);
		}
	</style>
</head>
<body>
	<h1>在内容之后插入图片——:after</h1>
	<p>
	You can use the :first-line pseudo-element <br>to add a special effect to the first line of a text!
	</p>
	<h2>在内容之前插入图片——:before</h2>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值