结构伪类选择器

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>结构伪类选择器</title>
    <style>
        /*要使该属性生效,元素必须是某个元素的子元素
         该选择符允许使用一个乘法因子(n)来作为换算方式,
         比如我们想选中所有的偶数子元素,那么选择符可以写成:E:nth-child(2n)*/
      li:nth-child(2n){
          background-color: white;
          color: aqua;
          width: 50px;
      }
        li:nth-child(2n+1){
            background-color:black;
            color: aqua;
            width: 50px;
        }
        ul{
            background-color: #cccccc;
            width: 100px;
        }
        li:nth-last-child(2){
            color: #ff7300;
        }
        /*掺杂了其他标签,这个例子用 li:nth-child(2)就不会有效果*/
        p:nth-of-type(2){
            color: blueviolet;
        }
    </style>
</head>
<body>
<ul>
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    <li>5</li>
    <li>6</li>
    <li>7</li>
    <li>8</li>
    <li>9</li>
</ul>
<ul>
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    <li>5</li>
    <li>6</li>
    <li>7</li>
    <li>8</li>
    <li>9</li>
</ul>
<div>
    <p>12</p>
    <div>伪段落</div>
    <p>13</p>
    <p>14</p>
    <p>15</p>
</div>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值