详解:last-child first-child 5

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style type="text/css">
        li:last-child
        {
            color: red;
        }
        .box1 p:last-child
        {
            color: blue;
        }
        .box1 p:first-child
        {
            color:yellow;
        }
    </style>
</head>
<body>
    <ul>
        <li>a1</li>
        <li>a2</li>
        <li>a3</li>
        <li>a4</li>
        <li>a5</li>
    </ul>
    <div class="box1">
        <p>1</p>
        <p>2</p>
        <p>3</p>
        <p>4</p>
    </div>
</body>
</html>

核心:first-child:第一个,所在元素的哦
last-child:最后一个,所在元素的哦

posted @ 2020-04-24 22:18  贵哥的编程之路  阅读(8)  评论(0)    收藏  举报