Style Sheets
  Home arrow Style Sheets arrow Page 2 - CSS Shorthand at a Glance
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
Moblin 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
STYLE SHEETS

CSS Shorthand at a Glance
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 17
    2005-02-08

    Table of Contents:
  • CSS Shorthand at a Glance
  • Basic CSS rules
  • Font shorthand property
  • Background shorthand property
  • Margin shorthand property
  • Padding shorthand property
  • Border shorthand property
  • List-style shorthand property

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    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:

    p {

         font-family: Arial, Helvetica, sans-serif;

         font-size: 12px;

         font-weight: bold;

    }

    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:

    p {

         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.

    More Style Sheets Articles
    More By Alejandro Gervasio


       ·  Here's a tight reference about the most common CSS shorthand properties,...
       · I always thought this stuff was common sense...Guess I took it for granted... I...
       ·  I agree with you about writing clean CSS code. That's the right way to...
     

    STYLE SHEETS ARTICLES

    - Creating Gradients for Individual Containers...
    - Creating Gradients for Web Page Headers with...
    - SEO Scrolling Frames Problem Solved
    - Building Cross-Browser Background Effects wi...
    - CSS: Pseudo
    - Using PNG Images to Build Background Effects
    - CSS: Continuing the Clarification of CSS Cla...
    - CSS: Top Secret Classification
    - CSS: Dimensions
    - CSS: Margins and Padding
    - CSS: Crossing the Border
    - CSS: Text, Fonts, and Tables
    - CSS: Working with Text
    - CSS: Backgrounds
    - CSS for the Newbie







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway