伪元素种类:
伪类种类:
伪元素和伪类之所以这么容易混淆,是因为他们的效果类似而且写法相仿,但实际上css3为了区分两者,已经明确规定了伪类用一个冒号来表示,而伪元素则用两个冒号来表示。但因为兼容性的问题,所以现在大部分还是统一的单冒号。
伪元素
1.first-line伪元素
first-line伪元素对段落内容的第一个格式化应用特殊样式。注意,第一行的长度取决于很多因素,包括页面宽度,字体大小等等。选择器"p:first-line"不会匹配任何真实的HTML元素,而是通过UA(也就是浏览器)给第一行加上 虚拟标签序列(fictional tag sequence),然后匹配这个东西。
比如:这段文本
<p>This is a somewhat long HTML paragraph that
will be broken into several
lines. The first line will be identified
by a fictional tag sequence. The other lines
will be treated as ordinary lines in the
paragraph.</p>
会被UA加上虚拟标签序列,像下面这样:
<p><p:first-line>This is a somewhat long HTML paragraph that</p:first-line>
will be broken into several
lines. The first line will be identified
by a fictional tag sequence. The other lines
will be treated as ordinary lines in the
paragraph.</p>
:first-line伪元素只能用于块级容器元素