学习第八十一行

对于html,里面有伪类选择器,

  1. :hover

    • 当鼠标悬停在元素上时应用样式。
    a:hover {
        color: red;
    }
    
  2. :active

    • 当元素被激活(如被点击)时应用样式。
    button:active {
        background-color: blue;
    }
    
  3. :focus

    • 当元素获得焦点时应用样式,通常用于输入框。
    input:focus {
        border: 2px solid green;
    }
    
  4. :first-child

    • 选择父元素的第一个子元素。
    p:first-child {
        font-weight: bold;
    }
    
  5. :last-child

    • 选择父元素的最后一个子元素。
    p:last-child {
        font-style: italic;
    }
    
  6. :nth-child(n)

    • 选择父元素的第 n 个子元素,可以使用公式。
    li:nth-child(2) {
        color: orange; /* 选择第二个子元素 */
    }
    li:nth-child(odd) {
        background-color: lightgray; /* 选择所有奇数子元素 */
    }
    
  7. :not(selector)

    • 选择不匹配指定选择器的元素。
    div:not(.active) {
        opacity: 0.5;
    }
    
  8. :checked

    • 选择被选中的复选框或单选框。
    input[type="checkbox"]:checked {
        background-color: yellow;
    }
    
  9. :disabled

    • 选择禁用状态的输入元素。
    input:disabled {
        background-color: lightgray;
    }
    

使用示例

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        a:hover {
            color: red;
        }
        li:nth-child(odd) {
            background-color: lightgray;
        }
        input:focus {
            border: 2px solid green;
        }
    </style>
</head>
<body>
    <a href="#">悬停我</a>
    <ul>
        <li>项目 1</li>
        <li>项目 2</li>
        <li>项目 3</li>
    </ul>
    <input type="text" placeholder="点击我">
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值