选择器
:link :选择未被访问的链接
:visited:选取已被访问的链接
:active:选择活动链接
:hover :鼠标指针浮动在上面的元素
:focus :选择具有焦点的
:first-child:父元素的首个子元素
:nth-child(i): 在这里只有满足以下两个条件才会执行:1.元素的类名是 :前的类名。2.元素是其父元素的第i个子元素。选择器与优先级
Last updated
:link :选择未被访问的链接
:visited:选取已被访问的链接
:active:选择活动链接
:hover :鼠标指针浮动在上面的元素
:focus :选择具有焦点的
:first-child:父元素的首个子元素
:nth-child(i): 在这里只有满足以下两个条件才会执行:1.元素的类名是 :前的类名。2.元素是其父元素的第i个子元素。Last updated
:first-letter :用于选取指定选择器的首字母
:first-line :选取指定选择器的首行
:before : 选择器在被选元素的内容前面插入内容
:after : 选择器在被选元素的内容后面插入内容[attribute] 选择带有attribute属性的元素
[attribute=value] 选择所有使用attribute=value的元素
[attribute~=value] 选择attribute属性包含value的元素
[attribute|=value]:选择attribute属性以value开头的元素p::before {
content: ">> ";
}p::first-line {
font-weight: bold;
color: blue;
}p::first-letter {
font-size: 2em;
color: red;
}<div>
<div class="pip">1</div>
<div class="pip">2</div>
<div class="pip">3</div>
</div>
.pip:nth-child(2) {
align-self: flex-end;
}
在这个例子中,.pip:nth-child(2) 会选择包含文本 "2" 的 <div> 元素。
注:在这里只有满足以下两个条件才会执行:
1.元素的类名是 pip。
2.元素是其父元素的第二个子元素。<div class="rtl">
<p>This paragraph is selected.</p> <!-- 直接作为 .rtl 元素的子元素 -->
<div>
<p>This paragraph is not selected.</p> <!-- 不是 .rtl 元素的直接子元素 -->
</div>
</div>