Require properties appropriate for display
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
Even though you can define any group of properties together in a CSS rule, some of them will be ignored due to the display of the element. This leads to extra cruft in your CSS and misunderstandings around how a rule should work.
For display: inline, the width, height, margin-top, margin-bottom, and float properties have no effect because inline elements don't have a formal box with which to apply the styles. The margin-left and margin-right properties still work reliably for indentation purposes but the other margin settings do not. The float property is sometimes used as a fix for the IE6 double-margin bug.
Other general rules based on display are:
-
display: inline-blockshould not usefloat. -
display: blockshould not usevertical-align. -
display: table-*should not usemargin(and all variants) orfloat.
Removing the ignored or problematic properties decreases file size thereby improving performance.
Rule Details
Rule ID: display-property-grouping
This rule is aimed at flagging properties that don't work based with the display property being used. The ultimate goal is to produce a smaller, clearer CSS file without unnecessary code. As such, the rule warns when it finds:
-
display: inlineused withwidth,height,margin,margin-top,margin-bottom, andfloat. -
display: inline-blockused withfloat. -
display: blockused withvertical-align. -
display: table-*used withmargin(and all variants) orfloat.
The following patterns are considered warnings:
/* inline with height */
.mybox {
display: inline;
height: 25px;
}
/* inline-block with float */
.mybox {
display: inline-block;
float: left;
}
/* table-cell and margin */
.mybox {
display: table-cell;
margin: 10px;
}The following patterns are considered okay and do not cause warnings:
/* inline with margin-left */
.mybox {
display: inline;
margin-left: 10px;
}
/* table and margin */
.mybox {
display: table;
margin-bottom: 10px;
}