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

久伴 2019年9月22日16:27:49 评论 70

代码举例

<!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会变红

久伴

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: