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>后代选择器</title>
    <style>
      /* 包含在ol里的都可以 */
      ol li {
        color: red;
      }
      ol a {
        color: royalblue;
      }
    </style>
  </head>
  <body>
    <ol>
      <li>我是ol的孩子</li>
      <li>我是ol的孩子</li>
      <li>我是ol的孩子</li>
      <a href="#">我是a</a>
    </ol>
    <ul>
      <li>我是ul的孩子</li>
      <li>我是ul的孩子</li>
      <li>我是ul的孩子</li>
    </ul>
  </body>
</html>

后代选择器

子代选择器

<!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>子代选择器</title>
    <style>
      /* 选出的是亲儿子 */
      div > a {
        color: red;
      }
    </style>
  </head>
  <body>
    <div class="nav">
      <a href="#">儿子</a>
      <p>
        <a href="#">孙子</a>
      </p>
    </div>
  </body>
</html>

子代选择器

并集选择器

<!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>并集选择器</title>
    <style>
      /* 将溯琳和琳玉变红 */
      /* div,
      p {
        color: red;
      } */
      /* 全部变成红色 */
      div,
      p,
      .pin li {
        color: red;
      }
      /* 并集选择器一般竖着写 */
    </style>
  </head>
  <body>
    <div>溯琳</div>
    <p>琳玉</p>
    <span>溯鱼</span>
    <ul class="pin">
      <li>小溯琳</li>
      <li>小琳玉</li>
      <li>小溯鱼</li>
    </ul>
  </body>
</html>

并集选择器

伪类选择器

链接伪类选择器

<!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>链接伪类选择器</title>
    <style>
      /* a:link      选择所有未被访问的链接
         a:visited   选择所有已被访问的链接
         a:hover     选择鼠标指针位于其上的链接
         a:active    选择活动链接(鼠标按下未弹起的链接)
         按照顺序写
         */
      a {
        text-decoration: none;
      }
      a:link {
        color: red;
      }
      a:visited {
        color: green;
      }
      a:hover {
        color: blue;
      }
      a:active {
        color: blueviolet;
      }
    </style>
  </head>
  <body>
    <a href="#">溯琳</a>
  </body>
</html>

a:link 前
伪类1
a:visited 后
伪类2
a:hover 划入
伪类3
a:active 点击不松
伪类4

:focus 伪类选择器

<!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>:focus 伪类选择器</title>
    <style>
      /* 
      :focus 伪类选择器用于选取获得焦点的表单元素
      一般只用于input元素
         */
      input:focus {
        background: red;
      }
    </style>
  </head>
  <body>
    <input type="text" />
    <input type="text" />
    <input type="text" />
  </body>
</html>

:focus 伪类选择器
喜欢的点个关注,每天更新博客

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值