|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionOne of the main advantages of using CSS is the large reduction in web page
download time. To style text, you used to have to use the
But why stop there? By using CSS shorthand properties you can reduce the size of your CSS document even more. FontUse: font: 1em/1.5em bold italic serif
...instead of font-size: 1em;
line-height: 1.5em;
font-weight: bold;
font-style: italic;
font-family: serif
This CSS shorthand property
will only work if you're specifying both the BackgroundUse: background: #fff url(image.gif) no-repeat top left
...instead of background-color: #fff;
background-image: url(image.gif);
background-repeat: no-repeat;
background-position: top left;
Omit any of these commands from the background CSS shorthand property, and the browser
will use the default values. If you leave out the
ListsUse: list-style: disc outside url(image.gif)
...instead of list-style: #fff;
list-style-type: disc;
list-style-position: outside;
list-style-image: url(image.gif)
Leave out any of these CSS
commands from the shorthand rule, and the browser will use the default values
for each, namely Margin & paddingThere are a number of different CSS shorthand commands for margin and
padding, depending on how many of the sides of the containing element have the
same Four different valuesUse: margin: 2px 1px 3px 4px (top, right, bottom, left)
...instead of margin-top: 2px;
margin-right: 1px;
margin-bottom: 3px;
margin-left: 4px
Three different valuesUse: margin: 5em 1em 3em (top, right and left, bottom)
...instead of margin-top: 5em;
margin-right: 1em;
margin-bottom: 3em;
margin-left: 1em
Two different valuesUse: margin: 5% 1% (top and bottom, right and left)
...instead of margin-top: 5%;
margin-right: 1%;
margin-bottom: 5%;
margin-left: 1%
One different valueUse: margin: 0 (top, bottom, right and left)
...instead of margin-top: 0;
margin-right: 0;
margin-bottom: 0;
margin-left: 0
The above rules also apply to BorderUse: border: 1px black solid
...instead of border-width: 1px;
border-color: black;
border-style: solid
Use: border-right: 1px black solid
...instead of border-right-width: 1px;
border-right-color: black;
border-right-style: solid
(You can substitute right with The above CSS shorthand rules can be conveniently combined with the shorthand rules used by margin and padding as shown below.
The borders on this box can be achieved with the following CSS command: border: 8px solid #336;
border-left: 10px solid #ccf;
border-top: 10px solid #ccf
You can achieve exactly the same effect by using: border: 8px solid #336;
border-width: 10px 8px 8px 10px
border-color: #ccf #336 #336 #ccf
ConclusionCSS shorthand properties are great! They're a great way to reduce the amount of code contained in a CSS document, allowing for faster download times and easier editing. Now who can argue with that?
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||