久久久久久久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?)
主站蜘蛛池模板: 国产一区二区三区视频 | 免费看黄视频网站 | 国产毛片视频 | 久久久久国产一区二区三区 | 看片网站在线 | 日韩在线h | 91av免费看| 亚州精品天堂中文字幕 | 久久久观看| 中文字幕一区二区三区精彩视频 | 亚洲精品第一 | 青青草av在线播放 | 国产日韩欧美一区二区 | 精品国产乱码久久久久久丨区2区 | 久久99蜜桃综合影院免费观看 | 久久99精品久久久97夜夜嗨 | 国产成人免费视频 | 亚洲欧美在线视频 | 国产高清视频一区二区 | 黄色av免费网站 | 欧美精品一区二区免费视频 | 日日夜夜天天 | 无码日韩精品一区二区免费 | 亚洲福利一区 | 久热精品在线 | 久久久精品网站 | 久久久国产精品一区 | 福利久久| 国产人成精品一区二区三 | 一区二区三区四区日韩 | 天天综合国产 | 亚洲精品区| 久久一久久 | 久久国产精品一区 | 一区二区av | 免费一二区 | 亚洲精品欧美 | 狠狠av | 欧美日韩午夜精品 | 黄色欧美在线 | 久久福利电影 |