大家好,欢迎来到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