CSS教程16 CSS的僞元素Pseudo Elements

僞元素吸附在選擇上和pseudo classes僞類很像,像這樣selector:pseudoelement{property: value;}。有四種方式。

First letters and First lines 首字母和首行

  first-letter僞元素作用到元素的第一個字母,first-line作用到元素的頂行。你可以,例如爲段落創建一個drop caps和首行加粗。

Example Source Code [www.52css.com]
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)圖片。

Example Source Code [www.52css.com]
blockquote:before {
content: open-quote;
}
blockquote:after {
content: close-quote;
}
li:before {
content: "POW: "
}
p:before {
content: url(images/jam.jpg)
}
  聽起來不錯吧,可惜大部分用戶不能體會到before或after的效果,因爲IE不支持。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章