Quick Tip 6 – CSS Shorthand

CSS Shorthand is another method which is regularly used to help cut down the size of Style Sheets, however trying to remember all shorthand tricks can be a bit tricky sometimes, so here is a handy list of the ones I use on a regular basis.
Quick Tip Gary

Boxes

Long
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
margin-left: 0px;

Shorthand (Every Value Different)
margin: top right bottom left;
margin: 0px 0px 0px 0px;

Long
margin: 20px 10px 20px 10px;

Shorthand (Equal Top and Bottom, Equal Left and Right)
margin: top-bottom left-right;
margin: 20px 10px;

All Values
margin: 10px;

Colour

Long
color: #FFFFFF;
color: #33CCFF;

Shorthand
color: #FFF;
color: #3CFF;

Backgrounds

Long
background-color: #000;
background-image: url (bg.jpg);
background-repeat: no-repeat;
background-position:top left;
background-attachment: scroll;

Shorthand
background: #000 url(bg.jpg) no-repeat top left scroll;

Fonts

Long
font-style: italic;
font-variant: normal;
font-weight: bold;
font-size: 0.8em;
line-height: 1.6em;
font-family: Georgia, Times New Roman, Times, serif;

Shorthand
font: italic normal bold 0.8em/1.6em Georgia, Times New Roman, Times, serif;

Borders

Long
border-width: 1px;
border-style: dashed;
border-color: #000;

Shorthand
border: 1px dashed #000;

or

border-width: top left bottom right;
border-width: 1px 2px 3px 4px;

List Styles

Long
list-style-type: circle;
list-style-position: inside;
list-style-image: url (img.jpg);

Shorthand
list-style: circle inside url (img.jpg);

Outline

Long
outline-color: #000;
outline-style: dotted;
outline-width: 1px;

Shorthand
outline: #000 dotted 1px;

Related posts:

  1. Quick Tip 5 – Compact CSS
  2. Quick Tip 7 – CSS !Important
  3. Quick Tip 9 – CSS min height
  4. Quick Tip 2 – CSS Text Shadow
  5. Quick Tip 10 – CSS Vertical Alignment

Tags: ,

Leave a Reply

Contact Us Today...

For more information regarding any of our services or to arrange a free consultation simply send us a message or call 02920 290 080 for Cardiff and 01179 000 482 for Bristol.

Firefox 4 Beta

Mozilla have released the first beta version of Firefox 4. The latest version of this browser will include better support for many of the new web technologies, a new add on manager, crash protection from third party plugins and accelerated hardware support. One of the most obvious changes is that the tabs have now been moved [...]
» more

Cardiff: 02920 290 080 Bristol: 01179 000 482