Planning Your Stylesheet - The Definitive Guide
Planning Your Stylesheet - The Definitive Guide
Planning Your Stylesheet - The Definitive Guide
March 2008
Commenting your stylesheet makes it much easier to find the information or the commands you're looking for.
Last updated - This information can quickly let developers know about recent changes made to the file:
References - Comments can also be used as a quick reference for the main style guides applied throughout
the site:
Reminders and notes - Leaving reminders and notes for yourself and other developers can help avoid
confusion later:
Define general rules and main classes at the top of the stylesheet
1 de 4 1/9/2008 14:15
Planning your stylesheet - the definitive guide http://www.webcredible.co.uk/user-friendly-resources/css/planning-sty...
Then, list the classes that will be most commonly used across the site, for example:
The order of the HTML should be used to determine the order of the CSS sections. CSS files can sometimes be
large and commands difficult to find. Having some correlation between the HTML and CSS file makes it easier to
locate how an element is being styled.
Using the correct selector type means your CSS file can be significantly reduced in size:
2. Ids - These are unique identifiers and should only be used once within a document. Ids should be used to
style major structural sections of a web page such as the header or the footer.
Too many ids or classes can overload the HTML and the CSS files unnecessarily. Try and define as many rules as
possible by referencing elements and/or ids by nesting the selectors.
Because each of the list items has a common parent, descendant selectors can simplify the CSS markup as follow:
2 de 4 1/9/2008 14:15
Planning your stylesheet - the definitive guide http://www.webcredible.co.uk/user-friendly-resources/css/planning-sty...
Don't name classes and ids based on their color or position as these may change in time. Try and give them a
name that's likely to remain relevant over time. Also, use hyphens ahead of underscores as certain old browsers
have a hard time understanding the latter.
Use a common naming system for your classes and ids. It will save a lot of time and confusion when developing,
debugging and updating documents.
By nesting CSS selectors (i.e. using more than one CSS selector in one command) we can apply styles by
navigating the HTML document tree. For example, to apply a colour of red to all paragraphs within a div, we can
use the following rule:
Some CSS commands inherit from their parents whereas others don't. The use of nesting means you don't have to
declare the same properties over and over again.
Generally speaking, text-related CSS commands (e.g. , ) are inherited by descendant elements,
whereas layout-related commands (e.g. , ) aren't inherited .
You can avoid specifying the same set of properties several times by grouping the selectors that share the same
CSS declarations together. For example:
This article was written by Brigitte Simard. Brigitte's crazy about accessibility and CSS - so crazy that she works for
Webcredible, an industry leading user experience consultancy2, helping to make the Internet a better place for
everyone. She spends much of her time working on the world's most accessible CMS3 and is very good at CSS
training4 .
What next?
Get a highly accessible CSS website through our accessible CSS web design6 expertise
Get our accessible and usable CMS3 so your site offers outstanding accessibility
Attend our interactive intermediate CSS training4 and advanced CSS training7 courses
3 de 4 1/9/2008 14:15
Planning your stylesheet - the definitive guide http://www.webcredible.co.uk/user-friendly-resources/css/planning-sty...
All our CSS articles are available for republishing, provided the author bio and links in the bio remain intact. You
8
can also use our RSS news feed to republish all of our CSS articles.
Links
1. http://www.webcredible.co.uk/jobs/usability.shtml
2. http://www.webcredible.co.uk/
3. http://www.webcredible.co.uk/services/accessible-cms.shtml
4. http://www.webcredible.co.uk/services/css-training-fund.shtml
5. http://www.webcredible.co.uk/user-friendly-resources/css/
6. http://www.webcredible.co.uk/services/web-design.shtml
7. http://www.webcredible.co.uk/services/css-training.shtml
8. http://www.webcredible.co.uk/user-friendly-resources/css.rss
9. http://del.icio.us/post?url=http://www.webcredible.co.uk/user-friendly-resources/css/planning-
stylesheet.shtml&title=Planning%20your%20stylesheet%20-%20the%20definitive%20guide
10. http://digg.com/submit?phase=3&url=http://www.webcredible.co.uk/user-friendly-resources/css/planning-
stylesheet.shtml
11. http://reddit.com/submit?url=http://www.webcredible.co.uk/user-friendly-resources/css/planning-
stylesheet.shtml&title=Planning%20your%20stylesheet%20-%20the%20definitive%20guide
12. http://slashdot.org/bookmark.pl?url=http://www.webcredible.co.uk/user-friendly-resources/css/planning-
stylesheet.shtml&title=Planning%20your%20stylesheet%20-%20the%20definitive%20guide
13. http://www.stumbleupon.com/submit?url=http://www.webcredible.co.uk/user-friendly-resources
/css/planning-stylesheet.shtml&title=Planning%20your%20stylesheet%20-%20the%20definitive%20guide
14. http://www.technorati.com/faves?add=http://www.webcredible.co.uk/user-friendly-resources/css/planning-
stylesheet.shtml
15. http://myweb2.search.yahoo.com/myresults
/bookmarklet?t=Planning%20your%20stylesheet%20-%20the%20definitive%20guide&u=http:
//www.webcredible.co.uk/user-friendly-resources/css/planning-stylesheet.shtml
16. http://www.webcredible.co.uk/user-friendly-resources/tellfriend.shtml?urlis=http://www.webcredible.co.uk
/user-friendly-resources/css/planning-stylesheet.shtml&
titleis=Planning%20your%20stylesheet%20-%20the%20definitive%20guide
4 de 4 1/9/2008 14:15