CSS选择器:root、not、empty、target

CSS选择器:root、not、empty、target伪类选择器 1 root DOCTYPEhtmlh en headmetachar UTF 8 metaname viewport content width device

大家好,欢迎来到IT知识分享网。

伪类选择器

1.root

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style type="text/css">
        /* root */
        :root{
            background-color: violet;
        }

    </style>
</head>
<body>
    <div >
        这是我的第一篇博客!
    </div>
</body>
</html>

效果如下:
在这里插入图片描述
若同时给body添加样式,结果如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style type="text/css">
        /* root */
        :root{
            background-color: violet;
        }
        body{
            background-color: wheat;
        }

    </style>
</head>
<body>
    <div >
        这是我的第一篇博客!
    </div>
</body>
</html>

在这里插入图片描述

2.not

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style type="text/css">
        /* not */
        div *:not(h1){
            color: teal;
        }
    </style>
</head>
<body>
    <div >
        <h1>这是我的第一篇博客!</h1>
        <h2>这是我的第一篇博客!</h2>
        <p>这是我的第一篇博客!</p>
    </div>
</body>
</html>

在这里插入图片描述

3.empt

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style type="text/css">
        /* emoty:元素内容为空白时使用的样式 */
        :empty{
            background-color: tomato;
        }
    </style>
</head>
<body>
    <table border="1px">
        <tr>
            <td>123</td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td>123</td>
        </tr>
        
    </table>
</body>
</html>

在这里插入图片描述

4.target

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style type="text/css">
        /* target */
        :target{
            background-color:pink;
        }
    </style>
</head>
<body>
    <a href="#a1">点击跳转111</a>
    <a href="#a2">点击跳转222</a>
    <div id=a1>111</div>
    <div id="a2">222</div>
</body>
</html>

在这里插入图片描述
在这里插入图片描述

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/155109.html

(0)
上一篇 2025-02-21 17:25
下一篇 2025-02-21 17:33

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注微信