I need to remove all of the default css stylesheets drupal attaches to my theme. It's a pretty simple theme & site, and I don't want to bloat it with 1400+ lines of css that won't be used. One of the things that gets me with drupal theming is I spend half my time individually resetting drupal's default css instead of developing my own.

I noticed a topic around which involved a patch, that added the ability to remove default drupal stylesheets via the themes .info file - this was great until I realised that the css files were also removed in the admin theme (for which I am using Garland), making things pretty messy. I'd like to be able to individually remove the attached stylesheet elements for css files I don't want from the html (like system.css and default.css), to ease up the code and put a tiny little less strain on the server by opening up less connections - so removing instead of overriding is preffered.

So I'd like to do it through template.php - there are a few 5.x solutions which don't seem to work on 6.x

Anyone know of a decent way to remove the default css?

Comments

leahcim.2707’s picture

I was trying to get the same thing done and for me this works, but I'm not sure if it is the correct way as I'm still new to Drupal:

in "template.php" I added the following function:

function phptemplate_preprocess_page(&$vars)
{
	$css	=		$vars['css'];
	unset($css['all']['module']['modules/system/system.css']);
	unset($css['all']['module']['modules/system/defaults.css']);
	$vars['styles'] = drupal_get_css($css);
}

I think after adding the function you need to go to /admin/build/themes so that Drupal recognises the function.

iamsuriyan’s picture

Thanks!

dharmanerd’s picture

You can remove print $styles from page.tpl.php. You'll also have to add link or import tags to include the theme style (style.css) and any other styles you want attached. It's really easy to just copy from the source code before you remove the "print $styles".

I would be careful about removing styles, because you may end up breaking modules which use ajax/javascript and css.

-steve.

------------------------------------------------
http://www.designbrigade.com

jozzhart’s picture

Howdy,

With drupal 6.x, you can use the theme.info file to overwrite the default system css files. For example, to over write the system menu default styling simply add:

stylesheets[all][] = system-menus.css

here is further explaination........
http://www.lullabot.com/blog/fixing-menu-css-themers-6

davidwhthomas’s picture

This is the simplest way to do it ^

DT

mansspams’s picture

does not work!!! something is dynamicvally loading system.css straight from core :(

iancawthorne’s picture

This does work (I've just used it). http://drupal.org/node/263967

Hydrant Ltd
www.hydrant.co.uk

steften’s picture

I found another solution to control the default styles -
not to use the general default stylesheet files, but instead of it
to copy, change and redirect the default stylesheet files for my concrete new theme.

It can be done as follows:
1) copy defaults.css from modules/system to the folder of your theme
2) make the necessary changes in the new defaults.css in your theme folder
3) redirect the css file path in your new theme page.tpl.php file -
this means, that change the defaults.css file path in the variable $styles with PHP preg_replace function

For example if the new theme (including the new copied defaults.css) files are in the folder sites/all/themes/drupal-test-theme,
then replace in your page.tpl.php file the code
print $styles
with the new code

$styles = preg_replace('/modules\/system\/defaults.css/', 'sites/all/themes/drupal-test-theme/defaults.css', $styles);
print $styles;
Ishus Media’s picture

I can't believe this ignorance from Drupal developers. Obviously they are not web designers.

Anonymous’s picture

The more I learn Drupal the more disappointed I become. So much cycles are being wasted in this bloated system. What - can't turn off CSS one by one?

Solutions:
1. Kill $styles ? The sub process(es) are still firing off from the core. Wasteful and bloated. nd I loose the "what should be cool" functionality.
2. Preg match / RegX - anyone know what the CPU cost is on that? (apparently not, it is taxing and should not be used for what is NORMALLY a simple task)
3. Overload (term used cautiously) - well we know PHP is a junky language (HTML + ECMA at best). Overload is not possible in PHP, and Drupal actually creates a work around for that (good job on implementing a solid pattern). But you now have the bloated wasteful Java type scenario. This is also cycle wasteful.

I am looking for a solution, non of these are really doing it for me. My CSS is SO TIGHT Drupal can't handle it with out me gutting the hell out of the template system. I already use my own header class because the header control in Drupal can't do what I need to do everyday.

I agree with Ishus.

...Still looking for a solution to a SIMPLE problem...

edit - solution:

// conditional for admin styles
if(!user_access('administer')){
$styles=null;
}

This will wipe the styles unless admin.

arcaneadam’s picture

http://drupal.org/node/155400 -> Documentation page for "Overriding the core and module stylesheets"

Adam A. Gregory
_____________________________
Drupal Developer and Consultant
https://goo.gl/QSJjb2
Acquia Certified Developer-Back end Specialist

jptaranto’s picture

Okay, now I know.... Use Omega!

Thorsten focus4’s picture

In Drupal 7 add this function to your template.php file in order to remove certain default CSS files from HTML:

function THEME_css_alter(&$css) {
  unset($css[drupal_get_path('module', 'system') . '/system.menus.css']);
  unset($css[drupal_get_path('module', 'system') . '/system.theme.css']);
  // unset($css[drupal_get_path('module', 'system') . '/system.messages.css']);
  // unset($css[drupal_get_path('module', 'system') . '/system.base.css']);
  // ...
}
dron.master’s picture

$styles = preg_replace('/
/i', '', $styles);