geekmas #1: Im the king - taking total control over the css in drupal

1 December 2007 mortendk

The first one were gonna start out with is actually a really really (really) simple trick that took me a while to actually get the grip on, yup havent said I was intelligent, and yes it is really obvious, but sometimes you cant se the forrest for all the trees.

How to take total crontrol over the css in the frontend of Drupal.
Every theamer must at some level have been bitching bout all the class definitions that we carry around in drupal, Offcourse we could just overwrite all these styles in out own style.css, but man that is a pain, and theres enought stuff to get a hold on allready in the styles, that we dont need a trillion overwrites.

So to get total control over whats going on in the front end, and yet again be a king in you own house do this:
Remove $style and add your own stylesheets by hand

In page.tpl.php

#000000">#0000BB"><?php #FF8000">// print $styles #0000BB">?>
<style type="text/css" media="screen">@import "#000000">#0000BB"><?php #007700">print #0000BB">base_path#007700">() . #0000BB">path_to_theme#007700">() #0000BB">?>/style.css";</style>
<style type="text/css" media="screen">@import "#000000">#0000BB"><?php #007700">print #0000BB">base_path#007700">() . #0000BB">drupal_get_path#007700">(#DD0000">'module'#007700">, #DD0000">'thickbox'#007700">) #0000BB">?>/thickbox.css";</style>
<!--[if IE]>
<style type="text/css" media="screen">@import "#000000">#0000BB"><?php #007700">print #0000BB">base_path#007700">() . #0000BB">path_to_theme#007700">() #0000BB">?>/style_ie.css";</style>
<![endif]-->
#000000">#0000BB"><?php #007700">print #0000BB">$scripts ?>

But off course this would resolve in the styles that are needed for a given modules wont be added automatically. You just have to do that by hand - yes that is a good thing, then you know whats actually is going on in the style sheets and whats defined, and not just let drupal do the thinking for you.
So to add the .css that a given module needs is not harder than to look into the module and add em

  <style type="text/css" media="screen">@import "#000000">#0000BB"><?php #007700">print #0000BB">base_path#007700">() . #0000BB">drupal_get_path#007700">(#DD0000">'module'#007700">, #DD0000">'MODULENAME'#007700">) #0000BB">?>/MODULENAME.css";</style>

In drupal 6 of what I understand you can actually remove the .css styles you dont want from a module - somebody is gonna get a beer, for writing that patch!
But until then this is the approach im using to get some kind of sanity into the all the css stuff thats going on in drupal (yeah i hate "em" - nuff said!).

Wow, I spent some time

Wow, I spent some time poking around on this site and I have never seen worse spelling on a blog, ever.

Anonymous 8 December, 2007 - 16:00

are ya sure? -then you

are ya sure? -then you should read my danish its even worse...

- og jer er da fuldstændigt ligeglad brokkerøv, anonyme kællinger kan for at sige det pænt sutter mine boller.

mortendk 8 December, 2007 - 20:18

It is so sad when

It is so sad when *anonymous* people comment on, of all the things, the spellings!

You have a great blog here and thanks for all the wonderful info about Drupal.

Divya 22 December, 2007 - 19:58

But I think there are 2

But I think there are 2 problem:
* inserting css this way you will not be able to use "css compression" in drupal config page
* Every time you add a new module you need to modify page.tpl.php (or every page-foo.tpl.php), what is sooo sad.

boheme 7 July, 2008 - 01:44
The content of this field is kept private and will not be shown publicly.
@codingdesigner @chriscoyier off course it wins its powered by #teamsass ;) 25 min 5 sec ago
3,785

DrupalCon Denver 2012 - I am a Speaker!

good Stüff

Mothership - a clean up the crap "theme"

Miro - a open atrium theme:
more info & comments

freya rocks

the progress for my premature daughter can be folllowed here:
Freya Rocks
sorry its in danish

Give some Love to the development of the mothership

Flattr this

User login

Recent comments

give some luv

drupal member ...

geek royale