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