久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

為什么在 CSS 中不建議按 ID 選擇?

Why selecting by ID is not recommended in CSS?(為什么在 CSS 中不建議按 ID 選擇?)
本文介紹了為什么在 CSS 中不建議按 ID 選擇?的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

在 CSS Lint 中,他們不建議使用 id 來選擇元素.我信任 CSS Lint,因?yàn)樗怯蓪?CSS 非常了解和深入的聰明人編寫的.但我想知道這是什么原因?為什么用 id 選擇不是一件好事?

In CSS Lint, they don't recommend using an id for selecting elements. I trust CSS Lint because it written by smart people who know CSS very good and in depth. But I want to know what are reasons of this? Why is selecting with an id not a good thing?

推薦答案

CSSLint 給出了他們?yōu)槭裁刺岢鼋ㄗh的指南:

CSSLint gives a guide to why they make their recommendations:

ID 不應(yīng)該在選擇器中使用,因?yàn)檫@些規(guī)則與 HTML 耦合太緊密,沒有重用的可能性.最好在選擇器中使用類,然后將類應(yīng)用于頁面中的元素.此外,ID 會(huì)影響您的特異性,并可能導(dǎo)致特異性戰(zhàn)爭.

IDs shouldn't be used in selectors because these rules are too tightly coupled with the HTML and have no possibility of reuse. It's much preferred to use classes in selectors and then apply a class to an element in the page. Additionally, IDs impact your specificity and can lead to specificity wars.

(來自 禁止選擇器中的 ID.)

基本上,如果您構(gòu)建代碼以使用類而不是 ID,您的代碼可以更通用且可重用,這通常是一件好事.此外,特異性是一件很難理解的事情,并且可能會(huì)導(dǎo)致難以發(fā)現(xiàn)的錯(cuò)誤,因此如果您省略 ID 選擇器,您就不太可能以意想不到的方式解決沖突的規(guī)則.

Basically, if you structure your code to use classes rather than IDs, your code can be more general and reusable, which is generally a good thing. Furthermore, specificity is a hard thing to get your head around, and can cause bugs that are hard to find, so if you omit ID selectors, you're less likely to have conflicting rules resolved in unexpected ways.

這篇關(guān)于為什么在 CSS 中不建議按 ID 選擇?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

CSS selector when :target empty(:target 為空時(shí)的 CSS 選擇器)
Does the CSS direct decendant (gt;) not have any value in selectivity?(CSS 直接后代 (gt;) 在選擇性方面沒有任何價(jià)值嗎?)
Using querySelectorAll(). Is the result returned by the method ordered?(使用 querySelectorAll().方法返回的結(jié)果是否有序?)
Safari bug :first-child doesn#39;t update display:block when items are removed with JS(Safari 錯(cuò)誤:當(dāng)使用 JS 刪除項(xiàng)目時(shí),first-child 不更新 display:block)
nth-Child CSS selectors(nth-子 CSS 選擇器)
Using same ID for multiple HTML tags?(對多個(gè) HTML 標(biāo)簽使用相同的 ID?)
主站蜘蛛池模板: 久久久久国产一区二区三区四区 | 国产欧美精品一区二区 | 草久免费视频 | 免费久久久 | 日本三级在线网站 | 久久久久无码国产精品一区 | 日韩精品一区二区三区在线观看 | 国产a区 | 日本一区二区高清不卡 | 日韩亚洲视频在线 | 亚洲精品福利视频 | 国产情侣啪啪 | 午夜视频网站 | 91福利网址 | 日韩精品中文字幕一区二区三区 | 国产伦精品一区二区三区四区视频 | va精品| 亚洲一区二区三区 | 国产97色| 岛国一区 | 在线日韩不卡 | 91视频免费视频 | 日韩av一区二区在线观看 | 成人av在线大片 | 欧美在线日韩 | 亚洲精品久久久一区二区三区 | 午夜精品在线 | 黄网站涩免费蜜桃网站 | 日韩在线免费视频 | 一区二区三区中文字幕 | 99精品免费久久久久久久久日本 | 国产精品99精品久久免费 | 韩国av一区二区 | 亚洲永久字幕 | 91久久视频| 午夜视频在线 | 国产专区在线 | 99精品久久| 98久久| 中国一级大毛片 | 91亚洲国产亚洲国产 |