css3 - css的偽類(lèi)作用?
問(wèn)題描述
如圖 這是我在刷面試題得時(shí)候 碰見(jiàn)的 想問(wèn)一下大神 有什么具體的區(qū)別?反正我寫(xiě)的時(shí)候 是沒(méi)有發(fā)現(xiàn) 至于作用我還是知道的
問(wèn)題解答
回答1:單冒號(hào)(:)用于CSS3偽類(lèi),雙冒號(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)和偽元素名稱(chēng)組成。雙冒號(hào)是在當(dāng)前規(guī)范中引入的,用于區(qū)分偽類(lèi)和偽元素。但是偽類(lèi)兼容現(xiàn)存樣式,瀏覽器需要同時(shí)支持舊的偽類(lèi),比如: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
偽類(lèi) https://developer.mozilla.org/zh-CN/docs/Web/CSS/Pseudo-classes
相關(guān)文章:
1. docker gitlab 如何git clone?2. 關(guān)于docker下的nginx壓力測(cè)試3. angular.js - angularjs的自定義過(guò)濾器如何給文字加顏色?4. docker不顯示端口映射呢?5. nignx - docker內(nèi)nginx 80端口被占用6. javascript - windows下如何使用babel,遇到了困惑7. dockerfile - [docker build image失敗- npm install]8. debian - docker依賴(lài)的aufs-tools源碼哪里可以找到啊?9. 老師您的微信號(hào)是多少?10. 在windows下安裝docker Toolbox 啟動(dòng)Docker Quickstart Terminal 失敗!
