XML technologies / CSS / CSS Cookbook / General topics / Structuring stylesheet content properly

(Excerpt from “CSS Kochbuch” by Christopher Schmitt)

Problem

You want to structure stylesheet content so that it is as easy as possible to maintain.

Solution

CSS rules can be structured by grouping a page’s visual elements. The following list suggests an order for grouping stylesheet elements:

  • HTML elements (h1–h6, p, a, lists, links, images)

  • Typography

  • Page layout (headers, content, page navigation, global navigation, subnavigation, sidebar, footers)

  • Form tags (form, fieldset, label, legend

  • Content (entry, event, news)

Here are comments from a stylesheet that group CSS code into different sections:

/* Typografie und Farben
------------------------------------ */
[CSS-Code]
/* Struktur
------------------------------------ */
[CSS-Code]
/* Kopfzeilen
------------------------------------ */
[CSS-Code]
/* Bilder/Grafiken
------------------------------------ */
[CSS-Code]
/* Listen
------------------------------------ */
[CSS-Code]
/* Formurlarelemente
------------------------------------ */
[CSS-Code]
/* Kommentare
------------------------------------ */
[CSS-Code]
/* Seitenleiste
------------------------------------ */
[CSS-Code]
/* Gemeinsame Elemente
------------------------------------ */
[CSS-Code]

Discussion

What works for one person may not help another. This recommendation combines personal experience with best practices and should work well for small to medium-sized websites.

You probably have your own preferences for different projects, and another structure may work better in your situation. Visit your favorite websites and examine their stylesheets for other ways of organizing them.

See also

  

 

 

 

back to top