CSS-伪类

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width: 100px;
            height: 100px;
            background-color: red;
        }
        /*伪类hover,当鼠标移上去*/
        .active:hover{
            background-color: green;
        }
        /*伪类disabled,当被禁用时*/
        .active1:disabled{
            width: 100px;
            height: 100px;
            background-color: black;
            color:white;
        }
        /*伪类checkbox,当被选中时*/
        /*后面的加号是兄弟选择器,该行的意思是,当checkbox被选中时,找到与.active2同父级下,并且相邻的,并且在active2之后的active3,
          找到后把该标签样式设为宽高等于100px,颜色设为蓝色【因为要相邻,所以只能有一个】*/
        .active2:checked + .active3{
            width: 100px;
            height: 100px;
            background-color:blue;
            
        }
        /*focus,当有焦点时(经常用于text),当点击时,其实也是有焦点时(经常用于button)*/
        button{
            background-color: black;
        }
        button:focus{
            background-color: rebeccapurple;
        }
        /*first-child,last-child,找第一个元素或最后一个元素,注意:这是伪类,不是选择器*/
        .active4 ul li:first-child{
            color: blue;
        }
        .active4 ul li:last-child{
            color: green;
        }
        /*nth-child,找到指定序数的标签,括号内的值可以填写:odd奇数,even偶数,数字*/
        table tr:nth-child(even){
            background-color: green;
        }
    </style>
</head>
<body>
    <div class="active"></div>
    <button class="active1" disabled="disabled">按钮</button>
    <input class="active2" type="checkbox" />
    <div class="active3"></div>
    <div class="active3"></div>
    <button>你好</button>
    <div class="active4">
        <ul>
            <li>123</li>
            <li>123</li>
            <li>123</li>
            <li>123</li>
            <li>123</li>
        </ul>
    </div>
    <table style="border: 1px solid black; width: 500px;">
        <tr>
            <td>4</td>
            <td>5</td>
            <td>6</td>
        </tr>
        <tr>
            <td>4</td>
            <td>5</td>
            <td>6</td>
        </tr><tr>
            <td>4</td>
            <td>5</td>
            <td>6</td>
        </tr><tr>
            <td>4</td>
            <td>5</td>
            <td>6</td>
        </tr><tr>
            <td>4</td>
            <td>5</td>
            <td>6</td>
        </tr>
    </table>
</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值