CSS Shorthand List

August 12th, 2009

Using these CSS shorthand techniques will save you valuable time and spare you the monotony.



Margin and Padding

Rather than type out a CSS statement for each side, margin-top, margin-right and so on combine them in one line. Tip: if the value for a particular side is 0, leave it at that and don’t bother typing anymore.

margin: margin-top | margin-right | margin-bottom | margin-left;
EXAMPLE= margin: 0 5px 0 0;

padding: padding-top | padding-right | padding-bottom | padding-left;
EXAMPLE= padding: 0 5px 0 0;




Borders

Combine the width, style and color of the border in one line. Tip: this works with border-left or border-right as well

Border: border-width | border-style | border-color
EXAMPLE= border: 1px solid black;




Background

Combine the color, image, repeat, attachment and position. Tip: skip the attributes you don’t need.

background: background-color | background-image | background-attachment | background-position;
EXAMPLE= background: #336699 url(images/bg.gif) fixed left center;




Font

Combine style, variant, weight, size, line height and family in one line

font: font-style | font-variant | font-weight | line-height | font-family;
EXAMPLE= font: italic small-caps 18px bold 24px Arial, Helvetica, sans-serif;




List

Combine type, position and image.

list: list-style-type | list-style-position | list-style-image;
EXAMPLE= list: disc inside url(images/mybullet.gif);

CSS

  1.  
    No comments yet.
     
Post a Comment
  1. No trackbacks yet.
You must be logged in to post a comment.