XML technologies / CSS / CSS Cookbook / General topics / Organizing stylesheet files

(Excerpt from “CSS Kochbuch” by Christopher Schmitt)

Problem

You want to manage and organize stylesheet files as effectively as possible.

Solution

Manage stylesheets by storing them in their own directory. For example, the following files are stored in a directory named css, itself inside the folder assets.

/_assets/css/print.css
/_assets/css/screen.css

For large or complex websites, it may help to store CSS rules in separate files according to their purpose rather than media type (print, screen, etc.). In this example, they occupy the same directory as the simple version.

/_assets/css/layout.css
/_assets/css/color-imagery.css
/_assets/css/type.css

In the HTML file, include the individual files in the element head:

<link rel="stylesheet" type="text/css" media="print" href="/_assets/css/print.css" />
<link rel="stylesheet" type="text/css" media="screen" href="/_assets/css/screen.css" />

On large sites, the file screen.css may import further CSS files defining specific aspects of screen display. Here is an example of the beginning of screen.css:

/* weitere Stylesheets importieren */
@import url("/_assets/css/layout.css");
@import url("farbdefinitionen.css");
@import url("typ.css");

Discussion

On small to medium-sized sites, placing external stylesheets (see the recipe Document types and their effects on browser rendering) in separate files for specific media types (print, screen, etc.) works well.

On larger or more complex sites, however, this approach can make it difficult to search files and understand how CSS instructions are organized.

There is currently no standard or recommendation for managing CSS files. As with the previous recipe, another approach may work better for you. You will probably need to experiment with file and content organization until you find a suitable solution.

See also

The recipe Applying styles to a web page for more information on external stylesheets.

  

 

 

 

back to top