Disallow IDs in selectors
Pages 49
-
LoadingHome
-
LoadingAbout
-
LoadingAvoid un anchored hovers
-
LoadingBeware of box model size
-
LoadingBuild System
-
LoadingBuild System Integration
-
LoadingBulletproof font face
-
LoadingCommand line interface
-
LoadingContributing
-
LoadingDeveloper Guide
-
LoadingDisallow !important
-
LoadingDisallow @import
-
LoadingDisallow adjoining classes
-
LoadingDisallow box sizing
-
LoadingDisallow duplicate properties
-
LoadingDisallow empty rules
-
LoadingDisallow negative text indent
-
LoadingDisallow non alphabetical
-
LoadingDisallow outline:none
-
LoadingDisallow overqualified elements
-
LoadingDisallow qualified headings
-
LoadingDisallow star hack
-
LoadingDisallow too many floats
-
LoadingDisallow underscore hack
-
LoadingDisallow units for zero values
-
LoadingDisallow universal selector
-
LoadingDon't use too many web fonts
-
LoadingIDE integration
-
LoadingNew Release
-
LoadingRequire all gradient definitions
-
LoadingRequire fallback colors
-
LoadingRequire shorthand properties
-
LoadingRequire use of known properties
-
LoadingRules
-
LoadingRules by ID
-
LoadingSource Code
-
LoadingUnit Tests
-
LoadingUsing in a Node.js Application
-
LoadingWorking with Rules
Clone this wiki locally
For years, developers have treated IDs as the way to say "that thing!" However, IDs have a downside: they are completely unique and therefore cannot be reused. You could potentially style every element on your page with an ID selector but you would lose a lot of the benefit of CSS in the process.
One of CSS's benefits is the ability to reuse style rules in multiple places. When you start out with an ID selector, you're automatically limiting that style to a single element. Suppose you have this:
#header a {
color: black;
}This style is only useful within the element with the ID of header. But now suppose that you want another section of the page to be styled the same way, you'll probably end up defining a new class that does the same thing, such as:
#header a,
.callout a {
color: black;
}Once you've gotten to this point, you might as well just use the class and not mention the ID:
.callout a {
color: black;
}Eventually you will end up needing or wanting to reuse the style specified with the ID, and you'll end up defining a class for that purpose. By not using IDs from the start, you allow for the maximum level of reusability with your CSS.
Rule Details
Rule ID: ids
This rule is aimed at improving maintainability by flagging the use of IDs in selectors. Every instance of an ID will result in a warning.
The following patterns are considered warnings:
#mybox {
display: block;
}
.mybox #go {
color: red;
}Additional Reading
``$ {webkit-tap-highlight-color: rgba(255,255,0,0);}