10 09/2014

css单双冒号的区别

最后更新: Wed Sep 10 2014 12:29:11 GMT+0800

经常会看到 :before 和 ::before 的写法,区别何在?

(至少目前)没有区别!

区别在于?

  • 单冒号 表示伪类 pseudo-classes
  • 双冒号 表示伪元素 pseudo-elements

This [double-colon] notation is introduced … in order to establish a discrimination between pseudo-classes and pseudo-elements. For compatibility with existing style sheets, user agents must also accept the previous one-colon notation for pseudo-elements introduced in CSS levels 1 and 2 (namely, :first-line, :first-letter, :before and :after). This compatibility is not allowed for the new pseudo-elements introduced in CSS level 3.

就象火车并没有火,马路也没有马一样,很尴尬的约定俗成。但是,也许不久的将来会有区别。via What’s the Difference Between “:before” and “::before”?