前端学习笔记二:CSS(6)伪类和伪元素

继续:
这个例子,我管它叫多变的类和元素~~(跟女生一样)~~ :

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title></title>
	</head>
	<style type="text/css">
		a{
			text-decoration: none;
		}
		p:link{
			color: #050b80;
		}
		a:visited{
			color: #ff03fb;
		}
		a:hover{
			color: #18b307;
		}
		a:active{
			color: #dbdb04;
		}
		p:first-of-type{
			color: #56E1B8;
		}
		p:last-of-type{
			color: #00BFFF;
		}
		a:before{
			content: url(../../html/05%20BaiduCloud%20Menu/one/img/压缩包.png);
		}
		a:after{
			content: url(../../html/05%20BaiduCloud%20Menu/one/img/文件.png);
		}
	</style>
	<body>
		<div id="item">
			<p> 第一段文字:</br>问:拖欠话费,打一人物</p>
			<p> 第二段文字:</br>答:古明地恋</p>
			<p>厉害,这都知道!</p>
			<a href="https://www.baidu.com/" target="_blank">风骚的百度</a>
		</div>
	</body>
</html>

运行结果:
默认情况:
在这里插入图片描述
光标放在链接上:
在这里插入图片描述
正在点击链接:
在这里插入图片描述

可以看到同一个没有类和id的标签的内容有不一样的地方,这就是伪类和为元素的应用。
它可以替代在设计网页的时候为一块内容里的首元素和末元素特意新建的子类。

通常(这次)用到的伪类样式有如下:

选择器示例说明
:linkp:link选择p标签里的所有的链接
:visiteda:visited选择a标签里访问过的链接
:hovera:hover选择a标签里被光标覆盖的链接
:activea:active选择a标签里被点击的链接
:first-child / :last-childp:first-child / p:last-child选择所有p元素的第一个/最后一个元素
:first-of-type / :last-of-typep:first-of-type / p:last-of-type选择的每一个p元素都是其父元素的第一个p元素
:beforep:before在每个p元素之前插入内容
:afterp:after子每个p元素之后插入内容
:first-lette rp:first-letter选择每个p元素的第一个字母
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值