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.
Cruising StackOverflow, I come up with this:
http://stackoverflow.com/questions/2168855/css-url-whats-better/2168861#2168861
According to the W3C, apparently the spec says they are optional, and if used, must be appropriately paired. I think it's cleaner to omit them, unless you absolutely need to quote special characters (whitespace or parentheses, usually) in the URI. If you've got literal whitespace or parentheses in your URIs, however, you've got bigger problems...
I'm in the process of writing a style guide for my teammates as well, and I encountered this via Google. :)