选择器

99 阅读1分钟

### 高级选择器

<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>
        /* 后代选择器,先选其祖父级,空格,在指定元素 */
        .box p{
            color:red;
        }
        /* 子选择器,先选其父级,任何在大于指定元素,只选其下一级的元素 */
        .boc>p{
            color:green;
        }
        /* 通配符选择器,选择全部标签 */
        *{
            color:blue;
        }
    </style>
</head>
<body>
    <div class=".box">
        <p>hello world</p>
        <div>
            <p>hhh</p>
        </div>
    </div>
    <p>我是兄弟级</p>
</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>Document</title>
    <style>
        .box{
            width: 300px;
            height: 300px;
            background-color: red;
        }
        /* 鼠标经过选择器(伪类选择器) */
        /* 鼠标经过时想要的样式 */
        .box:hover{
            background-color:yellow;
        }
    </style>
</head>
<body>
    <div class="box">
        鼠标经过
    </div>
</body>
</html>