A pseudo-element is made of two colons (::) followed by the name of the pseudo-element.
This :: notation is introduced by the current document in order to establish a discrimination between pseudo-classes and pseudo-elements. For compatibility with existing style 一天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.
單冒號(:)用於CSS3偽類,雙冒號(::)用於CSS3偽元素。
W3C關於CSS3選擇器的規格有一段描述:
A pseudo-element is made of two colons (::) followed by the name of the pseudo-element.
This :: notation is introduced by the current document in order to establish a discrimination between pseudo-classes and pseudo-elements. For compatibility with existing style 一天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.
簡單翻譯一下,大意就是,偽元素由雙冒號和偽元素名稱組成。雙冒號是在當前規範中引入的,用於區分偽類和偽元素。但偽類相容現存樣式,瀏覽器需要同時支援舊的偽類,如:first-line、:first-letter、:before、:after等。
那麼現在就可以完整的回答標題中的問題了,對於CSS2之前已有的偽元素,比如:before,單冒號和雙冒號的寫法::before作用是一樣的。
所以,如果你的網站只需要相容webkit、firefox、opera等瀏覽器,建議對於偽元素採用雙冒號的寫法,如果不得不兼容IE瀏覽器,還是用CSS2的單冒號寫法比較安全。
這種問題百度就知道了
參見:
偽元素 https://developer.mozilla.org/zh-CN/docs/Web/CSS/Pseudo-elements
偽類 https://developer.mozilla.org/zh-CN/docs/Web/CSS/Pseudo-classes