HTML and CSS Reference
In-Depth Information
When we're only setting one value, though, shorthand alternatives should not be used. If
a box only needs a bottom
margin
, use the
margin-bottom
property alone. Doing so
ensures that other
margin
values will not be overwritten, and we can easily identify which
side the
margin
is being applied to without much cognitive effort.
BAD CODE
1.
img {
2.
margin-top: 5px;
3.
margin-right: 10px;
4.
margin-bottom: 5px;
5.
margin-left: 10px;
6.
}
7.
button {
8.
padding: 0 0 0 20px;
9.
}
GOOD CODE
1.
img {
2.
margin: 5px 10px;
3.
}
4.
button {
5.
padding-left: 20px;
6.
}
Use Shorthand Hexadecimal Color Values
When available, use the three-character shorthand hexadecimal color value, and always use
lowercase characters within any hexadecimal color value. The idea, again, is to remain con-
sistent, prevent confusion, and embrace the syntax of the language the code is being written
in.
BAD CODE
1.
.module {
2.
background: #DDDDDD;
3.
color: #FF6600;
4.
}
GOOD CODE
1.
.module {
2.
background: #ddd;
3.
color: #f60;
4.
}
Search WWH ::
Custom Search