I want to use materializeCSS for my Blog content type. Problem is, when I import the stylesheet (I have set up my content type to process all HTML tags), it does not affect only the area of content of that content type, but it "leaks" to the rest of the theme, and changing overall theme look where CSS classes overlap (like default styling of H2 element in Materialize changes the whole look of the theme). Is there a way/module to have imported CSS stylesheet only affect the content it is imported to, but not the rest of the theme? I tried several modules that deal with context and CSS on sites, but neither of them works.

  • There is no way to make css only work on part of the page without adding extra selectors.
    – Jimmy Ko
    Sep 26, 2016 at 9:51

1 Answer 1


You can add your css only on Blog node pages so it does not impact site wide. Sample code

function MYTHEME_preprocess_node($vars) {
  if ($vars['#node']->type == 'blog') {
    drupal_add_css(drupal_get_path('module', 'mymodulename') . "/css/materializeCSS.css");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.