Hello guys,
I'd like to add some CSS to a couple of nodes. Is there a way to add a css file to those nodes only?

Comments

Cool_Goose’s picture

Taxonomy theme ?
------------------------------------------------------
Be Smart, Think Free, Choose OpenSource.

nevets’s picture

You do not say what or how you want the css different so this may or may not work for you need. One way is to use a different content type for those "special" nodes. If you just want different css for that type you could modify the line in node.tpl.php that looks something like

 <div class="node<?php if ($sticky) { print " sticky"; } ?><?php if (!$status) { print " node-unpublished"; } ?>">
 

and add a class to show node type (print 'node-' . $node->type;) change the line to (note that your themes node.tpl.php maybe different)

 <div class="node<?php print 'node-' . $node->type; if ($sticky) { print " sticky"; } ?><?php if (!$status) { print " node-unpublished"; } ?>">
 

Now you can add css rules that depends on node type (I will use page for the example) and add rules for the various elements using the type, something like

.node-page .title a {
color: red;
}

If you only want a few nodes themed different and can't (or don't want to) use a different content type you could change the line so it uses the nid (print 'node-' . $node->nid) as part of a class name, something like

 <div class="node<?php print 'node-' . $node->nid; if ($sticky) { print " sticky"; } ?><?php if (!$status) { print " node-unpublished"; } ?>">
 

Now you can add css rules that depends on node (using the nid, I will use a nid of 34 and add rules for the various elements using the type, something like

.node-34 .title a {
color: red;
}

You can of course use both $node->type and $node->nid.

If you want structural changes as well (different HTML) you can copy node.tpl.php to node-type.tpl.php (ex: node-page.tpl.php). You can read more about this at: http://drupal.org/node/17565