Drupal Pitfall: @import-ing CSS

Pitfall:

/* local.css */
@import "menu-styles.css"
@import "foobarbaz.css"

This pitfall causes style breakage when enabling Drupal’s CSS aggregation/caching.

Symptom

Some parts of the page (e.g., the primary links menu) look completely different after enabling caching.

Cause

Drupal’s CSS caching aggregates all your theme’s and your modules’ CSS files into one file (to minimize HTTP requests). But it doesn’t look for @import statements in CSS when doing so.

Solution

Declare all your CSS files in your theme’s .info file:

# mytheme.info
stylesheets[all][] = menu-styles.css
stylesheets[all][] = foobarbaz.css

and remove your CSS @import statements. (And as always, rebuild the theme registry for the changes to take effect.)

Share and Enjoy:
  • Reddit
  • Digg
  • Twitter
  • Slashdot
  • StumbleUpon
  • Google Bookmarks
  • Facebook
  • E-mail this story to a friend!
  • Print this article!
Posted on Wednesday, November 4th, 2009 at 6:00 pm and is filed under drupal. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a reply

Name (*)
Mail (will not be published) (*)
URI
Comment