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

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

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

問題描述

在 CSS Lint 中,他們不建議使用 id 來選擇元素.我信任 CSS Lint,因為它是由對 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 給出了他們為什么提出建議的指南:

CSSLint gives a guide to why they make their recommendations:

ID 不應該在選擇器中使用,因為這些規則與 HTML 耦合太緊密,沒有重用的可能性.最好在選擇器中使用類,然后將類應用于頁面中的元素.此外,ID 會影響您的特異性,并可能導致特異性戰爭.

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.)

基本上,如果您構建代碼以使用類而不是 ID,您的代碼可以更通用且可重用,這通常是一件好事.此外,特異性是一件很難理解的事情,并且可能會導致難以發現的錯誤,因此如果您省略 ID 選擇器,您就不太可能以意想不到的方式解決沖突的規則.

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.

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

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

相關文檔推薦

CSS selector when :target empty(:target 為空時的 CSS 選擇器)
Does the CSS direct decendant (gt;) not have any value in selectivity?(CSS 直接后代 (gt;) 在選擇性方面沒有任何價值嗎?)
Using querySelectorAll(). Is the result returned by the method ordered?(使用 querySelectorAll().方法返回的結果是否有序?)
Safari bug :first-child doesn#39;t update display:block when items are removed with JS(Safari 錯誤:當使用 JS 刪除項目時,first-child 不更新 display:block)
nth-Child CSS selectors(nth-子 CSS 選擇器)
Using same ID for multiple HTML tags?(對多個 HTML 標簽使用相同的 ID?)
主站蜘蛛池模板: 免费视频一区 | 日韩免费一区二区三区 | 免费看黄色大片 | 欧美性猛交xxxx | 日本免费中文字幕 | 成人免费视频国产免费麻豆 | 小sao货撅起屁股扒开c微博 | 中文字幕一区在线观看 | 国产区视频在线观看 | av免费观看网址 | 懂色av色吟av夜夜嗨 | 深夜福利网址 | 欧美一区二区在线 | 中文字幕av一区二区三区谷原希美 | 日韩成人影视 | 欧美日韩 | 97在线免费视频 | 免费av播放 | 2025国产精品 | 日韩av在线免费播放 | 91福利在线观看 | av黄色片 | 精品视频免费在线观看 | 在线观看黄色av | 国产视频www| 久久久久国产精品夜夜夜夜夜 | 中文字幕日韩在线观看 | 成人性色生活片 | 97人人艹 | 日本一级淫片色费放 | 国产香蕉在线观看 | 九色网址| 精品亚洲一区二区 | 国产精品欧美在线 | 日韩有码在线视频 | 欧美日韩成人一区二区 | 亚洲精品一区二区三区在线 | 亚洲一级大片 | 久久免费视频网站 | 亚洲人成免费 | 黄色网免费 |