HTML伪类选择器

伪类选择器:向某些选择器添加效果。
语法:
选择器:伪类{
declaration1;
declaration2;

}

类型

link:向未被访问过的链接添加样式。

<a href="http://www.baidu.com">百度一下</a>

<style>
	span{
		background-color: blue;
	}
</style>
	
<style>
    a:link{
	    background-color: red;
    }
</style>

在链接未被访问过时背景色为红色,访问过一次以后背景色变为蓝色。
visited:向已被访问的链接添加样式。

<a href="http://www.baidu.com">百度一下</a>

<style>
	span{
		background-color: blue;
	}
</style>	
		
<style>
	a:visited{
		background-color: red;
	}
</style>

在链接未被访问过时背景色为蓝色,访问过以后背景色变为红色。
hover:当鼠标悬浮在元素上方时,向元素添加样式。

<a href="http://www.baidu.com">百度一下</a>

<style>
	span{
		background-color: blue;
	}
</style>	
		
<style>
	a:hover{
		background-color: red;
	}
</style>

当鼠标不放置在链接上时背景色为蓝色,放在链接上时背景色变为红色。
active:向被激活的元素添加样式。

<a href="http://www.baidu.com">百度一下</a>

<style>
	span{
		background-color: blue;
	}
</style>	
		
<style>
	a:active{
		background-color: red;
	}
</style>

当该链接不被点击时背景色为蓝色,在鼠标点击而不松开时背景色为红色。
注意:若四种伪类选择器一起使用,顺序为link,visited ,hover ,active。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值