css3 - css的偽類作用?
問題描述

如圖 這是我在刷面試題得時候 碰見的 想問一下大神 有什么具體的區(qū)別?反正我寫的時候 是沒有發(fā)現(xiàn) 至于作用我還是知道的
問題解答
回答1:單冒號(:)用于CSS3偽類,雙冒號(::)用于CSS3偽元素。W3C關(guān)于CSS3選擇器的規(guī)范中有一段描述:
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 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.
簡單翻譯一下,大意就是,偽元素由雙冒號和偽元素名稱組成。雙冒號是在當前規(guī)范中引入的,用于區(qū)分偽類和偽元素。但是偽類兼容現(xiàn)存樣式,瀏覽器需要同時支持舊的偽類,比如:first-line、:first-letter、:before、:after等。
那么現(xiàn)在就可以完整的回答標題中的問題了,對于CSS2之前已有的偽元素,比如:before,單冒號和雙冒號的寫法::before作用是一樣的。
所以,如果你的網(wǎng)站只需要兼容webkit、firefox、opera等瀏覽器,建議對于偽元素采用雙冒號的寫法,如果不得不兼容IE瀏覽器,還是用CSS2的單冒號寫法比較安全。
回答2:這種問題百度就知道了
參見:
偽元素 https://developer.mozilla.org/zh-CN/docs/Web/CSS/Pseudo-elements
偽類 https://developer.mozilla.org/zh-CN/docs/Web/CSS/Pseudo-classes
相關(guān)文章:
1. boot2docker無法啟動2. java - 判斷數(shù)據(jù)在數(shù)據(jù)庫中是否已存在.3. android百度地圖定位問題4. javascript - JS new Date() 保存到 mongodb 中會早8個小時,我們這里是東八區(qū),mongodb 保存的是格林尼治時間5. javascript - 移動端上不能實現(xiàn)拖拽布局嗎?6. python - django models 為生成的html元素添加樣式。7. javascript - 關(guān)于圣杯布局的一點疑惑8. android - 圖片列表分組之后復(fù)用問題9. thinkPHP5中獲取數(shù)據(jù)庫數(shù)據(jù)后默認選中下拉框的值,傳遞到后臺消失不見。有圖有代碼,希望有人幫忙10. css - input間的間距和文字上下居中

網(wǎng)公網(wǎng)安備