Css first-of-type与last-of-type结构类

代码举例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>last-of-type</title>
    <style>
        div:last-of-type {
            color: red;
        }
    </style>
</head>
<body>
<div>1</div>
<p>2</p>
<div>3</div>
<section>
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
</section>
<div>56666</div>
<p>11111</p>
</body>
</html>

由此可见 56666和5会变红

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>last-of-type</title>
    <style>
        div:first-of-type {
            color: red;
        }
    </style>
</head>
<body>
<div>1</div>
<p>2</p>
<div>3</div>
<section>
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
</section>
<div>56666</div>
<p>11111</p>
</body>
</html>

由此可见 1和1会变红

点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注