偽元素吸附在選擇上和pseudo?classes偽類很像,像這樣selector:pseudoelement{property:?value;}。有四種方式。
First?letters?and?First?lines?首字母和首行
first-letter偽元素作用到元素的第一個字母,first-line作用到元素的頂行。你可以,例如為段落創建一個drop?caps和首行加粗。
p:first-letter?{
????font-size:?3em;
????float:?left;
}
p:first-line?{
????font-weight:?bold;
}
Before?and?after?前后
before和after用來聯系content屬性不使用HTML確定一個元素的內容位置。
content屬性值可以是:open-quote,close-quote,no-open-quote,no-close-quote,在引號標記里關閉任何字符串或使用url(imagename)圖片。
blockquote:before?{
????content:?open-quote;
}
blockquote:after?{
????content:?close-quote;
}
li:before?{
????content:?“POW:?“
}
p:before?{
????content:?url(images/jam.jpg)
}
聽起來不錯吧,可惜大部分用戶不能體會到before或after的效果,因為IE不支持。
