Even if shorthand properties are convenient to use, there are a few edge cases to keep in mind when using them:
background-color: red; background: url(images/bg.gif) no-repeat top right;will not set the color of the background to red but to background-color's default, transparent, as the second rule has precedence.
margin: 10px 5px 8px 5px;
Therefore, shorthand properties should be sparsely used.
This rule raises an issue each time a shorthand property is declared and its value contains more than one element.
.mybox {
margin: 10px 5px 15px; /* Noncompliant */
border-color: green; /* Compliant: value is a single element */
}
.mybox {
margin-top: 10px;
margin-right: 5px;
margin-bottom: 15px;
margin-left: 5px;
border-color: green;
}
| Property | Shorthand For |
|---|