在这堂课开始之前,我想先问大家一下:你们知道什么叫伪类选择器吗?
你已经知道了对吗?如果还不太了解,那就让我来揭晓下谜底吧。
伪类选择器:顾名思义,就是不是针对真正的元素使用的选择器。也就是说CSS中已经定义好的选择器,不能随便取名,更改属性。
它的使用方法如下:
选择器:伪元素{ 属性:值 }
eg: <style> a:link{ color:red } </style>
当然,伪元素选择器也可以配合类选择器一起使用,如下:
选择器 . 类名: 伪元素{ 属性:值 }
eg: <style> p.before(此处是p元素下class类名):hover{ color:red } </style>
一、Root选择器
root选择器将样式绑定到整个html页面,对 :root选择器进行操作相当于对整个html网页进行操纵。
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
<title>root选择器</title>
<style type="text/css">
:root{background-color:#ccc;}
body{background-color:#f00;}
</style>
</head>
<body>
<h1>root选择器</h1>
<p>我们都是这个小小宇宙里的小小尘埃<br/> 幸福太短暂<br>
不要在该奋斗的年纪选择了安逸。</p>
</body>
</html>
但是,要注意如果删除掉 :root 的选择器则body设置的属性值代表整个页面。将会变成