My answer will be more than you want, because I've seen a css files that was 60K long and consisted mostly of classes and ID's overwriting others - because no one knows how css works. They just keep adding things until they get the result they want.
.myClass { /* 0,0,1,0 */
top-margin: 1px;
padding: 3px;
}
#myid { /* 0,1,0,0 */
width: 80px;
height: 80px;
}
Repeat with space in between.
Now the important stuff.
- The comments are the specificity of the selector.
- Things should be ordered from least specific to most specific in the file.
- Within matching specificities, it should be alphabetical.
- There should be no more than one selector per definitiion - even if you could have put
them all in the same selector. That way you can find them later. And your specificity
doesn't get messed up. Hopefully you are using a compressor that can handle that
correctly.
- Classes and ID's should be specifically named to somewhat match where they are in
your system. In other words, classes at www.example.com can be called
.table
. If you need a new table class at www.example.com/foo/... it should be
named something like .foo-table
and should apply and be used by things
below it.
- All css should be in separate files from your html document and all modifications to
css should preferably be done by changing/adding classes and not by changing specific
style attributes at the element level.
I'm the only one I know that does it this way, but everyone who has used it since has said, "Damn, that makes it easy to find my CSS errors!"