I need to have a CSS class applied to certain content types. Some content types need the CSS class applied to them and other content types do not need it applied to them. Is there a way to specify this?

Comments

ameymudras’s picture

Hi

most themes provide a class according to the content type to the body.
so using this class you can give css to any element such that it is always according to content type

I love Drupal & working since 7.5+ years now in Drupal.

dman’s picture

as a specific example, this page on drupal.org contains

<div id="node-1819402" class="node clear-block node-type-forum">

so you can add css like

.node-type-forum {
  background-color:pink;
}

to pinkify all forum content type content.

The node level may not be useful enough for you, but other themes sometimes put the node type class into the body tag, so you may be able to use css chaining like

.node-type-forum .title{
  color:blue;
}
ameymudras’s picture

thats perfect...

I love Drupal & working since 7.5+ years now in Drupal.

rujikin’s picture

I am making a custom theme. No pre-made themes were quite what I wanted.

class="node-type-article"

Would this be correct? I just want to know how to associate it right now.

Ayesh’s picture

In case you can't see the node type in your theme, open node.tpl.php file from your theme's templates folder and add the following to where you have classes added to the most top level div.

print $node->type;

For example,
<div class=node-wrapper">
can be replaced with:
<div class=node-wrapper <?php print $node->type; ?>">

rujikin’s picture

Thanks! I found out the names of those classes. Time to format them :D

node-amendment-headers