selector {
property: value;
}
- Each selector is on its own line.
- Property-value pairs on their own lines.
- One-tab indentation and one semicolon.
- Trailing curly brace is flush left.
#selector-1,
#selector-2,
#selector-3 {
background: #fff;
color: #000;
}
#selector-1, #selector-2, #selector-3 {
background: #fff; color: #000;
}
#selector-1 { background: #fff; color: #000; }
#comment-form {
margin: 0;
}
#commentForm { /* Avoid camelcase. */
margin: 0;
}
#comment_form { /* Avoid underscores. */
margin: 0;
}
#c1-xr { /* What is a c1-xr?! Use a better name. */
margin: 0;
}
Avoid over-naming when HTML tags will suffice.
<div class="main">
<h1>Header</h1>
<p>Paragraph</p>
</div>
Except when you shouldn't. Let the code do the talking when it can.
/* Short comments: one line with no trailing space. */
#selector-1 {...
#selector-1 {
color: #000; /* A short comment can also follow one property/value pair. */
}
/*
For longer, multiple line comments that need more room,
add a newline before and after the comment.
Leave one line of space before the next block.
*/
#previous-block {
color: #000;
}
/* =Name of section
-------------------------------------------------------------- */
#selector-1 {...
Phrase based on what it is rather than where. Use the tag names to avoid style leakage.
div#page div.teaser ul.products li p.name
ul.products p.name
background-color: lime;
background-image: url('rofl.png');
background: url('woot.png') prange 0 50% repeat fixed;
If headings need to be uppercase, put a text-transform.
Test in IE, Firefox, and Safari often.
Don't build separate solutions for IE.
Set floated items to display-inline
. This fixes the double margin float bug in IE.
:link, :visited, :hover, :focus, :active
Avoids inheritance issues in IE.
Indeed I am. Our team is exploding in size, and ye olde startup-style cowboy coding is swiftly becoming a bug farm (as well as making mentoring and navigating foreign code painful).
I'm drawing lots of inspiration from http://www.phpied.com/css-coding-conventions/ as well, with modern updates. I'll let you know if I think of any improvements over what you've got already, most of my customizations are reflections of our gigantic codebase.