CSS教程16、CSS的偽元素PseudoElements[翻譯Htmldog]_CSS教程
教程Tag:暫無Tag,歡迎添加,賺取U幣!
偽元素吸附在選擇上和pseudo classes偽類很像,像這樣selector:pseudoelement{property: value;}。有四種方式。
First letters and First lines 首字母和首行
first-letter偽元素作用到元素的第一個字母,first-line作用到元素的頂行。你可以,例如為段落創(chuàng)建一個drop caps和首行加粗。
示例代碼 [hl5o.cn]
p:first-letter {
font-size: 3em;
float: left;
}
p:first-line {
font-weight: bold;
}
font-size: 3em;
float: left;
}
p:first-line {
font-weight: bold;
}
Before and after 前后
before和after用來聯(lián)系content屬性不使用HTML確定一個元素的內(nèi)容位置。
content屬性值可以是:open-quote,close-quote,no-open-quote,no-close-quote,在引號標記里關閉任何字符串或使用url(imagename)圖片。
示例代碼 [hl5o.cn]
blockquote:before {
content: open-quote;
}
blockquote:after {
content: close-quote;
}
li:before {
content: "POW: "
}
p:before {
content: url(images/jam.jpg)
}
content: open-quote;
}
blockquote:after {
content: close-quote;
}
li:before {
content: "POW: "
}
p:before {
content: url(images/jam.jpg)
}
聽起來不錯吧,可惜大部分用戶不能體會到before或after的效果,因為IE不支持。
相關CSS教程:
- 相關鏈接:
- 教程說明:
CSS教程-CSS教程16、CSS的偽元素PseudoElements[翻譯Htmldog]
。