Beruflich Dokumente
Kultur Dokumente
SHORTHAND
CSS properties are the aspect of the element that can be styled such as color, border, padding.
p { color: red; }
Property
Shorthand properties are designed to make it easier for authors - to save writing multiple declarations.
Shorthand properties include: background, border, border-color, border-style, border-width, border-top, border-right, borderbottom, border-left, font, liststyle, margin, outline and padding
In many cases, shorthand properties are defining one or more sides of an element.
In these cases, they are defined using one, two, three or four values.
The order that values are specified for two, three and four values is critical!
One value means that all four sides will be styled the same way. (top/right/bottom/left)
p { margin: 1em; }
One way to remember four values is to think clockwise starting at the top.
Another way to remember shorthand values is to use: TRouBLe top right bottom left
1. Margin
p { margin-top: 1em; margin-right: 1em; margin-bottom: 1em; margin-left: 1em; } p { margin: 1em; }
p { margin-top: 1em; margin-right: 2em; margin-bottom: 1em; margin-left: 2em; } p { margin: 1em 2em; }
p { margin-top: 1em; margin-right: 2em; margin-bottom: 4em; margin-left: 2em; } p { margin: 1em 2em 4em; }
p { margin-top: 1em; margin-right: 2em; margin-bottom: 4em; margin-left: 3em; } p { margin: 1em 2em 4em 3em; }
2. Padding
p { padding-top: 1em; padding-right: 1em; padding-bottom: 1em; padding-left: 1em; } p { padding: 1em; }
p { padding-top: 1em; padding-right: 2em; padding-bottom: 1em; padding-left: 2em; } p { padding: 1em 2em; }
p { padding-top: 1em; padding-right: 2em; padding-bottom: 4em; padding-left: 2em; } p { padding: 1em 2em 4em; }
p { padding-top: 1em; padding-right: 2em; padding-bottom: 4em; padding-left: 3em; } p { padding: 1em 2em 4em 3em; }
The default value for a property, when it hasnt been specified by authors is called the initial value.
3. Border-color
p { border-top-color: #999; border-right-color: #999; border-bottom-color: #999; border-left-color: #999; } p { border-color: #999; }
p { border-top-color: #999; border-right-color: #aaa; border-bottom-color: #999; border-left-color: #aaa; } p { border-color: #999 #aaa; }
p { border-top-color: #999; border-right-color: #aaa; border-bottom-color: #000; border-left-color: #aaa; } p { border-color: #999 #aaa #000; }
p { border-top-color: #999; border-right-color: #aaa; border-bottom-color: #000; border-left-color: #666; } p {border-color: #999 #aaa #000 #666;}
4. Border-width
p { border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; } p { border-width: 1px; }
p { border-top-width: 1px; border-right-width: 2px; border-bottom-width: 1px; border-left-width: 2px; } p { border-width: 1px 2px; }
p { border-top-width: 1px; border-right-width: 2px; border-bottom-width: 3px; border-left-width: 2px; } p { border-width: 1px 2px 3px; }
p { border-top-width: 1px; border-right-width: 3px; border-bottom-width: 4px; border-left-width: 1px; } p { border-width: 1px 3px 4px 1px; }
5. Border-style
p { border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; } p { border-style: solid; }
p { border-top-style: solid; border-right-style: dashed; border-bottom-style: solid; border-left-style: dashed; } p { border-style: solid dashed; }
p { border-top-style: ridged; border-right-style: dashed; border-bottom-style: solid; border-left-style: dashed; } p { border-style: ridge dashed solid;}
6. Border-top
7. Border-right
8. Border-bottom
9. Border-left
10. Border
11. Outline
Be aware that IE5, IE6 and even IE7 do not support outline.
12. Background
p p p p p
{ { { { {
13. Font
p p p p p p
{ { { { { {
font-style: normal; } font-variant: normal; } font-weight: normal; } font-size: medium; } line-height: normal; } font-family: [up to user agent]; }
14. List-style
p { list-style-type: disc; list-style-image: none; list-style-position: inside; } p { list-style: disc none inside; }
A recap
/* margin values */ p { margin: 1em; } p { margin: 1em 2em; } - (top/bottom left/right) p { margin: 1em 2em 4em; } - (top left/right bottom) p { margin: 1em 2em 4em 3em; } - (top right bottom left) /* padding values */ p { padding: 1em; } p { padding: 1em 2em; } - (top/bottom left/right) p { padding: 1em 2em 4em; } - (top left/right bottom) p { padding: 1em 2em 4em 3em; } - (top right bottom left) /* border-color values */ p { border-color: #999; } p { border-color: #999 #aaa; } - (top/bottom left/right) p { border-color: #999 #aaa #000; } - (top left/right bottom) p { border-color: #999 #aaa #000 #666; } - (top right bottom left) /* border-width values */ p { border-width: 1px; } p { border-width: 1px 2px; } - (top/bottom left/right) p { border-width: 1px 2px 3px; } - (top left/right bottom) p { border-width: 1px 3px 4px 1px; } - (top right bottom left)
/* border-style values */ p { border-style: solid; } p { border-style: solid dashed; } - (top/bottom left/right) p { border-style: ridge dashed solid; } - (top left/right bottom) p { border-style: ridge dashed solid inset; } - (top right bottom left) /* border values - order of values not critical */ p { border-top: 1px solid #000; } p { border-right: 1px solid #000; } p { border-bottom: 1px solid #000; } p { border-left: 1px solid #000; } p { border: 1px solid #000; } /* outline values - order of values not critical */ p { outline: 1px solid #000; } /* background values - order of values not critical */ p { background: #f00 url(a.gif) repeat fixed 0 0; } /* font values - order of values critical!! */ p { font: italic small-caps bold 1em/140% times, serif; } /* list-style values */ p { list-style: disc none inside; } - order not critical
Russ Weakley
Max Design
Site: maxdesign.com.au Twitter: twitter.com/russmaxdesign Slideshare: slideshare.net/maxdesign Linkedin: linkedin.com/in/russweakley