tags:

views:

33

answers:

2
drupal_add_css('override/files/style.css');

This kind of statement can't ensure the css is loaded last,

how can I do the trick?

+1  A: 

The CSS gets added in the order drupal_add_css() is called, which depends largely on the weight of the module or theme doing the calling, stored in the system table. Drupal.org's instructions on changing module weight also work for themes.

The other factor determining the order of drupal_add_css() is simply the order in which the containing function is called in the code of Drupal. template_preprocess_page(), for example, is always called after template_preprocess_node(), simply because the node goes in the page.

Scott Reynen
This doesn't sound like a valid solution.
A: 

if you look in the template.php theme file of the ninesixty theme you will find a solution.

The following function are called from the theme_preprocess_page hook:

function ninesixty_css_reorder($css) {
  global $theme_info, $base_theme_info;

  // Dig into the framework .info data.
  $framework = !empty($base_theme_info) ? $base_theme_info[0]->info : $theme_info->info;

  // Pull framework styles from the themes .info file and place them above all stylesheets.
  if (isset($framework['stylesheets'])) {
    foreach ($framework['stylesheets'] as $media => $styles_from_960) {
      // Setup framework group.
      if (isset($css[$media])) {
        $css[$media] = array_merge(array('framework' => array()), $css[$media]);
      }
      else {
        $css[$media]['framework'] = array();
      }
      foreach ($styles_from_960 as $style_from_960) {
        // Force framework styles to come first.
        if (strpos($style_from_960, 'framework') !== FALSE) {
          $framework_shift = $style_from_960;
          $remove_styles = array($style_from_960);
          // Handle styles that may be overridden from sub-themes.
          foreach ($css[$media]['theme'] as $style_from_var => $preprocess) {
            if ($style_from_960 != $style_from_var && basename($style_from_960) == basename($style_from_var)) {
              $framework_shift = $style_from_var;
              $remove_styles[] = $style_from_var;
              break;
            }
          }
          $css[$media]['framework'][$framework_shift] = TRUE;
          foreach ($remove_styles as $remove_style) {
            unset($css[$media]['theme'][$remove_style]);
          }
        }
      }
    }
  }

  return $css;
}
Tom