Drupal Pitfall: @import-ing CSS
Pitfall:
/* local.css */
@import "menu-styles.css"
@import "foobarbaz.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
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.)









Leave a reply