css3 - css的偽類作用?
問(wèn)題描述
如圖 這是我在刷面試題得時(shí)候 碰見(jiàn)的 想問(wèn)一下大神 有什么具體的區(qū)別?反正我寫(xiě)的時(shí)候 是沒(méi)有發(fā)現(xiàn) 至于作用我還是知道的
問(wèn)題解答
回答1:單冒號(hào)(:)用于CSS3偽類,雙冒號(hào)(::)用于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.
簡(jiǎn)單翻譯一下,大意就是,偽元素由雙冒號(hào)和偽元素名稱組成。雙冒號(hào)是在當(dāng)前規(guī)范中引入的,用于區(qū)分偽類和偽元素。但是偽類兼容現(xiàn)存樣式,瀏覽器需要同時(shí)支持舊的偽類,比如:first-line、:first-letter、:before、:after等。
那么現(xiàn)在就可以完整的回答標(biāo)題中的問(wèn)題了,對(duì)于CSS2之前已有的偽元素,比如:before,單冒號(hào)和雙冒號(hào)的寫(xiě)法::before作用是一樣的。
所以,如果你的網(wǎng)站只需要兼容webkit、firefox、opera等瀏覽器,建議對(duì)于偽元素采用雙冒號(hào)的寫(xiě)法,如果不得不兼容IE瀏覽器,還是用CSS2的單冒號(hào)寫(xiě)法比較安全。
回答2:這種問(wèn)題百度就知道了
參見(jiàn):
偽元素 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. javascript - vscode alt+shift+f 格式化js代碼,通不過(guò)eslint的代碼風(fēng)格檢查怎么辦。。。2. javascript - [js]為什么畫(huà)布里不出現(xiàn)圖片呢?在線等3. python - 如何判斷爬蟲(chóng)已經(jīng)成功登陸?4. html - vue項(xiàng)目中用到了elementUI問(wèn)題5. html5 - 有可以一次性把所有 css外部樣式轉(zhuǎn)為html標(biāo)簽內(nèi)style=" "的方法嗎?6. javascript - 如何將一個(gè)div始終固定在某個(gè)位置;無(wú)論屏幕和分辨率怎么變化;div位置始終不變7. javascript - 原生canvas中如何獲取到觸摸事件的canvas內(nèi)坐標(biāo)?8. javascript - 有什么比較好的網(wǎng)頁(yè)版shell前端組件?9. javascript - 這不是對(duì)象字面量函數(shù)嗎?為什么要new初始化?10. javascript - 求解答:實(shí)例對(duì)象調(diào)用constructor,此時(shí)constructor內(nèi)的this的指向?
