What could be simpler and faster than using CSS to set up your website? Using CSS shorthand to set up your website. While not all browsers support all of CSS shorthand's features, enough of them are supported to allow you to write tighter code, and create a website that loads more quickly.
CSS Shorthand at a Glance - Basic CSS rules (Page 2 of 8 )
Probably, as a seasoned Web developer, you already know the concepts. Still, letís have a quick look at a sample CSS rule, showing the different sections of it, and the corresponding names for each part. The following image illustrates the anatomy of a CSS rule:
As depicted above, a CSS rule consists of a selector element or group of elements, and a property declaration section, which can include one or many properties, and the values tied to each one of them. At this point, these definitions should be very familiar to most of us, but itís a useful reminder for those wishing to refresh some core concepts.
As we know, CSS rules allow us to define many property declarations for a selector, which usually is declared with a few lines of code. For instance, letís say we want to apply a CSS style to a paragraph element. We do it in the following way:
font-family: Arial, Helvetica, sans-serif;
The code listed above is a fairly common way to apply CSS styles to selectors, used by numerous developers in their Web pages. There are also many popular development tools such as Dreamweaver that will generate similar code when CSS styles are applied within a Web document. There is nothing wrong with this since it will work seamlessly on most browsers. However, the code might be greatly improved by just defining all of the selector property declarations in one line, using CSS shorthand:
font: bold 12px "Arial", Helvetica, sans-serif;
Weíve redefined our CSS declaration using the "font" shorthand property, which allows us to set values for all of the above properties utilizing one line, cutting our code close to half the size. This technique will have a high impact on the overall style files, reducing their sizes considerably and making our site much more efficient and faster to display.
Letís see in detail some of the most frequently used CSS shorthand properties, for easy implementation on our websites. This is not intended to be a full-blown CSS reference, as stated before. Instead, it can be a handy guide to quickly put CSS shortcuts into action and take advantage of their benefits. Weíll direct our attention to the most common CSS shorthand properties supported by today's browsers as well as some of the older ones.