Disallow adjoining classes
Pages 48
- Home
- About
- Avoid un anchored hovers
- Beware of box model size
- Build System
- Build System Integration
- Bulletproof font face
- Command line interface
- Contributing
- Developer Guide
- Disallow !important
- Disallow @import
- Disallow adjoining classes
- Disallow box sizing
- Disallow duplicate background images
- Disallow duplicate properties
- Disallow IDs in selectors
- Disallow negative text indent
- Disallow non alphabetical
- Disallow outline:none
- Disallow overqualified elements
- Disallow qualified headings
- Disallow selectors that look like regular expressions
- Disallow star hack
- Disallow too many floats
- Disallow underscore hack
- Disallow units for zero values
- Disallow universal selector
- Disallow unqualified attribute selectors
- Don't use too many font size declarations
- Don't use too many web fonts
- Headings should only be defined once
- IDE integration
- Ignoring parts of CSS during linting
- New Release
- Require all gradient definitions
- Require compatible vendor prefixes
- Require fallback colors
- Require properties appropriate for display
- Require shorthand properties
- Require standard property with vendor prefix
- Require use of known properties
- Rules
- Rules by ID
- Source Code
- Unit Tests
- Using in a Node.js Application
- Working with Rules
- Show 33 more pages…
Clone this wiki locally
Adjoining classes, sometimes also called class chaining, look like .foo.bar. While technically allowed in CSS, these aren't handled properly by Internet Explorer 6 and earlier. IE will match the selector as if it were simply '.bar' which means your selector will match more frequently than you intend it to and create cross-browser bugs.
Generally, it's better to define styles based on single classes instead of based on multiple classes being present. Consider the following:
.foo {
font-weight: bold;
}
.bar {
padding: 10px;
}
.foo.bar {
color: red;
}The rule for selector .foo.bar can be rewritten as a new class:
.foo {
font-weight: bold;
}
.bar {
padding: 10px;
}
.baz {
color: red;
}That new class, baz, must now be added to the original HTML element. This is actually more maintainable because the .baz rule may now be reused whereas the .foo.bar rule could only be used in that one instance.
Rule Details
Rule ID: adjoining-classes
This rule is intended to flag uses of adjoining classes that will fail in Internet Explorer 6 and earlier.
The following patterns are considered warnings:
.foo.bar {
border: 1px solid black;
}
.first .abc.def {
color: red;
}The following patterns are considered okay and do not cause a warning:
/* space in between classes */
.foo .bar {
border: 1px solid black;
}