CSS 7.6 伪类
1.链接的伪类
·a:link,普通的,未被访问的链接
·a:visited,已访问过的链接
·a:hover,鼠标指针在链接上时,hover ['hʌvɚ]徘徊
·a:active,鼠标点击链接时
·a:focus,向拥有键盘输入焦点的元素添加样式。
注1:有顺序要求(focus无顺序要求):
link -> visited -> hover -> active或
visited -> link -> hover -> active
注2:伪类名称对大小写不敏感。
注3:伪类可以与 CSS 类配合使用:
a.red : visited {color: #FF0000}
<a class="red" href="css_syntax.asp">CSS Syntax</a>
2.伪类:first-child,选择所有某元素(如p)中的第一个(p)。
例如1:
p:first-child { color:blue;}
li:first-child { color:blue;}
HTML中:
<div>
<p>These are the necessary steps:</p> //所有p中的第一个p
<ul>
<li>Intert Key</li> //所有li中的第一个li
<li>Turn key <strong>clockwise</strong></li>
<li>Push accelerator</li>
</ul>
<p>Do <em>not</em> push the brake at the same time as the accelerator.</p>
</div>
例如2:
p > i:first-child { color:blue;} //p的子元素中第一个i
HTML中:
<body>
<p>some <i>text</i>. some <i>text</i>.</p>
<p>some <i>text</i>. some <i>text</i>.</p>
</body>
例如3:
p:first-child i { color:blue;} //第一个p的后代i
HTML中:
<body>
<p>some <i>text</i>. some <i>text</i>.</p>
<p>some <i>text</i>. some <i>text</i>.</p>
</body>
3.伪类:lang(是language的缩写,为不同语言定义特殊规则)
一种特殊用法:
在HTML中:
<p>文字<q lang="no">段落中的引用的文字</q>文字</p>
在CSS中:
q:lang(no){ //匹配q元素的lang类=“no”的
quotes:“~” “~” //将quotes(q元素)定义为显示~和~(原来是“和”)
}
一般用法:
在HTML中:
<div lang=“en”>
·············
</div>
在CSS中:
div:lang(en) { color:red;}