CSS: Shortcuts

(Still on old news for you CSS-pros. I’m wondering why YOU’RE not writing this blog. All the comments have been more helpful than my posts!! LOL!)

Just wanted to jot these down so I could find them later:

font-weight: bold;
font-size: 10px;
font-family: Verdana,Arial,Helvetica,sans-serif;
shortcut:
font: bold 10px Verdana,Arial,Helvetica,sans-serif;

margin/padding shortcuts:
margin: top# right# bottom# left#
ie. margin: 5px 0px 2px 10px;
or
margin: top&bottom# left&right#
ie. margin: 10px 5px;

color shortcuts (websafe hex)
color: #000000;
shortcut: color: #000
color: #FFCC00;
shortcut: color: #FC0;

12 Responses to “CSS: Shortcuts”

  1. John Says:

    Oh, man, that font-style shortcut is great; I had just stumbled across the border hack a few days ago (border: 1px solid #000;), but the font-style cousin to it is even better. Thanks for posting this!

  2. pixelkitty Says:

    even better - anything with 0 value can be just 0

    so: 10px 0 5px 10px;
    :)

  3. KMB Says:

    Hi there - there is also a nifty shortcut for margin & padding, when your left and right side do have the same value:
    margin: 4px 6px 2px;
    4px = top ## 6px = right & left ## 2px = bottom
    I never used it, but there has to be a way so this comes in handy ;)

  4. PEP Says:

    the shortcut for margin & padding also works for top and bottom:

    padding: 2px 10px;

    will put 2px on top and bottom, 10px on left and right

  5. theresa Says:

    There’s also a background shortcut to declare all of the background properties:

    background: #ffffff url(image.gif) no-repeat top left;

    or other variants.

  6. Jenna Says:

    A good way to remember the margin/padding order is TRouBLe. Top. Right. Bottom. Left.

  7. rio Says:

    nice blog! just wanted to drop a notice that the International Webloggers’ Day is June 9, 2004! http://www.intlblogday.tk

  8. Nate Says:

    I can never remember the acronyms, but another way to remember the margin/padding number order is to just think of a clock - starting at high noon go clockwise = top, right, bottom, left (:00, :15, :30, :45). For whatever reason that method always stuck with me. Here’s a page with a little more shortcut info.

  9. Aldark Says:

    One thing I would recommend to CSS novices is to intially separate your information with a new line - then when it works modify it. Only because it tends to be easier to find an error or where you want to modify initially.
    W3Schools.com is a great CSS reference site.

  10. Julik Says:

    background: url(image url) left top no-repeat;
    essentially the most important here - horizontal position first, vertical position second (not vice-versa)

  11. Christine Says:

    Another tip: if using dynamic link pseudo-classes, always make sure to remember to put them in correct order.

    a:link, a:visited, a:hover, a:active.

    Great acronym to remember it is: LoVe HAte.

    And remember to add color/background-color both if using the other, otherwise UA’s could over ride your style rules.

  12. Jennifer Says:

    Saw this here (ALL the shortcuts)

    font
    font-weight, font-style, font-variant, font-size, line-height, font-family

    background
    background-color, background-image, background-repeat, background-attachment, background-position

    margin
    margin-top, margin-right, margin-bottom, margin-left

    padding
    padding-top, padding-right, padding-bottom, padding-left

    border
    border-width, border-style, border-color

    border-width
    border-top-width, border-right-width, border-bottom-width, border-left-width

    border-style
    border-top-style, border-right-style, border-bottom-style, border-left-style

    border-color
    border-top-color, border-right-color, border-bottom-color, border-left-color

    list-style
    list-style-type, list-style-position, list-style-image

    outline
    outline-color, outline-style, outline-width