伪类选择器:向某些选择器添加效果。
语法:
选择器:伪类{
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。