伪类选择器

链接伪类选择器:

/* 未访问的链接 */
a:link {
  color: #FF0000;
}

/* 已访问的链接 */
a:visited {
  color: #00FF00;
}

/* 鼠标悬停链接 */
a:hover {
  color: #FF00FF;
}

/* 已选择的链接 */
a:active {
  color: #0000FF;
}

代码即实现:

<!DOCTYPE html>
<html>
<head>
<style>
/* unvisited link */
a:link {
  color: red;
}

/* visited link */
a:visited {
  color: green;
}

/* mouse over link */
a:hover {
  color: hotpink;
}

/* selected link */
a:active {
  color: blue;
}
</style>
</head>
<body>

<h1>CSS 链接</h1>
<p><b><a href="/index.html" target="_blank">这是一个链接</a></b></p>
<p><b>注释:</b>在 CSS 定义中,a:hover 必须位于 a:link 和 a:visited 之后才能生效。</p>
<p><b>注释:</b>在 CSS 定义中,a:active 必须位于 a:hover 之后才能生效。</p>

</body>
</html>

https://www.w3school.com.cn/css/css_pseudo_classes.asp(详细伪类)

伪类列表元素

常用于列表的几个伪类元素我们需要知道的有:

  • :first-child:选取列表中的第一个元素;
  • :last-child:选取列表中的最后一个元素;
  • :nth-child():指定我们需要选取的元素,括号内的值可以是数字,自变量为n的表达式以及even或者是odd(也就是奇偶数)。                                                                                            
  • <style>
        li{
            font-size: 28px;
            list-style: none;
        }
        li:first-child{
            color: green;
            font-weight: bold;
        }
        li:last-child{
            color: red;
            font-weight: bold;
        }
        li:nth-child(3){
            color: #0000FF;
            font-weight: bold;
        }
    </style>
    ​
    <ul>
        <li>eoeo</li>
        <li>monster</li>
        <li>fire</li>
        <li>lucky</li>
        <li>tracer</li>
    </ul>

 

  • :link:未访问的链接,链接默认状态
  • :visited:已经访问过的链接
  • :active:获得焦点,链接激活的状态
  • :hover:鼠标放到链接上显示的状态

简单实例:

a:link{
    color: red;
    text-decoration: none;
}
a:visited{
    color: purple;
    text-decoration: line-through;
}
a:hover{
    color: green;
    text-decoration: underline;
}
a:active{
    color: blue;
    text-decoration: overline;
}
​
<ul>
    <li><a href="https://www.baidu.com/">百度一下</a></li>
    <li><a href="http://hxke.com/">好学课堂</a></li>
    <li><a href="#">鲸设网</a></li>
    <li><a href="https://www.9xkd.com/">侠课岛</a></li>
</ul>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值