CSS3

CSS3 知识量:11 - 43 - 138

2.9 否定伪类选择器><

什么是否定伪类选择器- 2.9.1 -

否定伪类选择器用来定位不匹配该选择器的元素。

否定伪类选择器的语法- 2.9.2 -

否定伪类选择器的语法很简单,形如:

E:not(F)

表示匹配所有除元素F以外的E元素。

否定伪类选择器的示例- 2.9.3 -

下面是一个否定伪类选择器的示例,功能是选择除第3段文字外的内容,并将字体设置为蓝色加粗显示。

<!DOCTYPE html>
<html>
    <head>
        <title>否定伪类选择器</title>
        <meta charset="UTF-8">
        <style type="text/css">
            div p:not(:nth-child(3)){
                color: blue;
                font-weight: 900;
            }
        </style>
    </head>
    <body>
        <h2>The Three Little Pigs</h2>
        <div>
            <p>Once upon a time there were three little pigs and the time came 
                for them to leave home and seek their fortunes.</p>
            <p>Before they left, their mother told them " Whatever you do , do it the best 
                that you can because that's the way to get along in the world.</p>
            <p>The first little pig built his house out of straw because it was the 
                easiest thing to do.</p>
            <p>The second little pig built his house out of sticks. This was a 
                little bit stronger than a straw house.</p>
            <p>The third little pig built his house out of bricks.</p>  
        </div>
    </body>
</html>

显示的效果为:

微信截图_20210812083855.png