日期:2014-05-17  浏览次数:20678 次

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不支持。