1.选择器

前提:亲儿子

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <style>
  8. /*前提:亲儿子*/
  9. .parent>p:first-child {
  10. color: red;
  11. }
  12. .parent>p:last-child {
  13. color: yellow;
  14. }
  15. .parent>p:nth-child(3) {
  16. color: green;
  17. }
  18. </style>
  19. </head>
  20. <body>
  21. <div class="parent">
  22. <p>hello world</p>
  23. <p>hello world</p>
  24. <p>hello world</p>
  25. <p>hello world</p>
  26. </div>
  27. </body>
  28. </html>

2.后代选择器

.parent>div{}亲儿子
.parent div{}选中parent之后的所有元素

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /*
        后代选择器
        .parent>div{}亲儿子
        .parent div{}选中parent之后的所有元素
        */
        .parent>div{
            color: red;
        }
        .parent div{
            font-size:40px;
        }
    </style>
</head>

<body>
    <div class="parent">
        <div>good</div>
        <div>hello</div>
        <ul>
            <li><div>child</div></li>
            <li><div>child</div></li>
        </ul>
    </div>

</body>

</html>

3.伪类选择器

a:hover{}
伪类选择器

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /*
        a:hover{

        }
        伪类选择器
        */
        a:hover{
            color:red;
        }
    </style>
</head>
<body>
    <a href="#">a</a>
</body>

</html>