偽元素種類:
偽類種類:
? ? ? 偽元素和偽類之所以這么容易混淆匆篓,是因為他們的效果類似而且寫法相仿,但實際上css3為了區(qū)分兩者寇窑,已經(jīng)明確規(guī)定了偽類用一個冒號來表示鸦概,而偽元素則用兩個冒號來表示。但因為兼容性的問題甩骏,所以現(xiàn)在大部分還是統(tǒng)一的單冒號窗市。
偽元素
1.first-line偽元素
first-line偽元素對段落內(nèi)容的第一個格式化應(yīng)用特殊樣式。注意饮笛,第一行的長度取決于很多因素咨察,包括頁面寬度,字體大小等等福青。選擇器"p:first-line"不會匹配任何真實的HTML元素扎拣,而是通過UA(也就是瀏覽器)給第一行加上 虛擬標(biāo)簽序列(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加上虛擬標(biāo)簽序列,像下面這樣:
<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偽元素只能用于塊級容器元素