Home

Lullabot

Lullabot Ideas

We know stuff. We empower you to know stuff too.

Drupal Module Development Deep Dive Week

London, UK
September 20-24, 2010

Fixing Menu CSS for Themers in Drupal 6

Blog by Jeff EatonSeptember 25, 2007 - 5:53am

In Lullabot Podcast 46, Jeff Robbins interviewed the Australian team of developers from the 2007 Full Code Press competition. The Drupal team in that competition narrowly lost to the 'custom CMS' team, and one of the things that threw them off was the combination of the contest's tight deadlines... and Drupal's notoriously difficult-to-override menu related CSS rules. Think about it: a contest was designed to show off tools make the best rapid development system for web sites, and Drupal's menu-related CSS ended up dragging the designer down rather than helping. That should be a sign to us that something needs fixing.

The underlying HTML that we generate when building menus isn't bad. Rather, it's the extremely specific rules that core applies to control subtle things like indentation, spacing, bullet icons, and so on for all the menus it generates. Overriding these styles using normal CSS cascade rules is nightmarish, because they're extremely specific -- and CSS gives precedence based on how specific a rule is. In addition, Drupal's menu related CSS rules are dumped into the general 'system.css' file, with everything from tabbed navigation CSS to the rules needed to make draggable textareas work. Simply writing a PHP snippet in template.php that hacks out system.css would break lots of other stuff.

Fortunately, fixing this problem appears to be really easy: so easy, in fact, that we can do it without breaking any APIs and without requiring any new syntax for theme developers. This issue on Drupal.org first splits out just the menu-related CSS rules into a separate system-menus.css file. Then, it cleans up the mechanism by which themes can 'override' other style sheets with their own copies. If a themer wants to entirely replace Drupal's menu styles, they can just copy system-menus.css into their theme directory, add it to their theme's .info file, and change it completely. Drupal will ignore the core version of that CSS file, using the theme's instead, and themers will no longer have to grapple with ugly CSS specificity hacks to make their menu tricks fly.

We've made lots of improvements to Drupal 6's theming system, and the ability to build 'pure' CSS themes using images, .css files, and a descriptive .info file, has the potential to put Drupal theming within reach of a wider range of designers and web artists. Please test it and give it a spin: if we can get this committed, the tiny change will make D6's killer improvements even more powerful.

Comments

Bevan (not verified) on October 7, 2007 - 5:27pm

Related discussion:

Related discussion: http://groups.drupal.org/node/6471
and a work in progress: http://groups.drupal.org/node/6355

Philippe Jadin (not verified) on September 25, 2007 - 7:26am

Why not simplify the system css ?

Imho it would be logical to change the system css to be more "generic". This way, it becomes easy for themers to overide the system css. The system css is often very interesting to keep, because they give good presentation for the admin/* pages.

A line must be drawn between styling of the drupal administration UI and the client website. Drupal system css should not have influence on the client menus.

Caleb G (not verified) on September 25, 2007 - 10:00am

That does not parse

a) That's what the 'admin theme' setting in Drupal is for

b) Making everything more modular/accessible is pretty much always a good idea. Conversely keeping things in one-monolithic-file makes modifications much more difficult to find/work-on.

c) There is no such thing as "generic css". Elements either have a style applied to them, or they don't. Even if Drupal didn't include any css that people would still have to worry about overriding all the different browser css settings out there. So again there is no such thing as 'generic css'. For any customization one is always overriding something.

d) The theme improvements in Drupal 6 will make it much easier to override things.

bevan (not verified) on September 25, 2007 - 9:27am

I agree. Has anyone tried

I agree. Has anyone tried changing the specificness of the particular css selectors that cause problems?

September 25, 2007 - 12:05pm Jeff Eaton

Not really.

One of the problems is that changing the rules would impact all of the themes that DO exist for Drupal already. Drupal 6.0 is in 'feature freeze' beta, where changes that break existing APIs, interfaces, and so on can only be made in emergencies (breaking bugs, security fixes, etc.)

The solution used in the patch that was linked doesn't break any of those things, just makes it possible for themes to drop the old css file and insert their own.

Recent

Drupal Voices 160: Moshe Weitzman on Page Rendering in Drupal 7

Podcast 9.02.2010

Drupal Voices 159: John Albin Wilkins on Drupal 7 Theming

Podcast 9.01.2010

Drupal Voices 158: Emma Jane Hogbin on PHP for Designers

Podcast 8.31.2010

Command Line Basics: More Editing with Vi/Vim

Video 8.31.2010

Lullabot's Back to School Sale

Blog 8.30.2010

Popular

Drupal Voices 160: Moshe Weitzman on Page Rendering in Drupal 7

Podcast 9.02.2010

Photo galleries with Views Attach

Article 6.01.2009

Drupal Voices 159: John Albin Wilkins on Drupal 7 Theming

Podcast 9.01.2010

Drupal Voices 158: Emma Jane Hogbin on PHP for Designers

Podcast 8.31.2010

Assembling Pages with Drupal

Article 7.17.2010
 
  • Home
  • Services
  • Events
  • Ideas
  • Store

Connect the Bots:

Twitter Facebook YouTube blip.tv All Posts Newsletter
  • Ideas
  • Blog
  • Podcasts
  • Videos
  • About
  • Contact
  • Jobs
  • Services
    • Training
  • Events
    • Training Workshops
    • Other Events
    • Conferences
    • Calendar
  • Products
    • Videos
    • Books
    • Swag
  • Ideas
    • Blog
    • Podcast
    • Videos
  • About
    • Philosophy
    • Team
    • Presskit
  • Contact
    • General
    • Work Inquiries
    • Mailing List