Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By hate90 on
hi, how can i style an specific node or a content type so i can give specific css to it
Comments
easy way use
easy way
use node--your_content_type.tpl.php and put the custom id in the wrapper so you can target it via css
more advanced way
implement yourtheme_template_preprocess_node or yourtheme_template_preprocess_page from template.php and tweak out the variables for attributes (classes)
--------------------------------------------------------------------------------------------------------
if you can use drupal why use others?
VicTheme.com
Some themes already include a
Some themes already include a class for the content type and other for the node in the div wrapper that surrounds the nodes output.
Step by step for a dummie..
Sorry my knowledge of php is very little to non and in general for me Drupal is still very complicated.
Could someone please explain step by step how I can achieve it so that a certain content type gets it's own css..?
Thanks in advance
What version of Drupal are
What version of Drupal are you using and what is the theme used?
Drupal 7.10 and CorporateClean
I have Drupal 7.10 and CorporateClean is the theme
If you inspect a node with a
If you inspect a node with a tool like firebug you will find it in wrapper div something like this
The one you want is the one that reflects the type, in this case 'node-blog'. So by prefixing your css with this class you can target specific node types so for example
would make the node title for blog teasers green
Thanks..really.. but
This is what Firebug shows"
The only thing I can see of use in this code is "node-type-page", but about all the content is of this, isn't it..? It is not the specific node/page name whichs' machine name is 'event'..
.page-node-17 h2
.page-node-17 h2 a
{
color:red;
}
Hi cyberdog_sk, does this
Hi cyberdog_sk, does this mean that the content type is 'page-node', and that so I have to create a page--page-node.tpl.php if I want to have all the 'files' of this content type to get the same css specifications..?
'page-node' tell you the
'page-node' tell you the first part of the path is 'node'. 'node-type-page' tells you the content type is 'page'. And no, you do not need 'page--page-node.tpl.php', the point of using the class allows you to target elements based on that class
css
To be clear, that code cyberdog gave you would go in your css file. It is telling the link (a) of any H2 heading on the page for node-17 to be red.
If you just edit the style.css file in the theme you are using and add that you will see the H2 links become red.
LAter you may want to read up on creating a sub-theme and adding an additional external style sheet. That way if you update your theme, it will not erase your changes.
A list of some of the Drupal sites I have designed and/or developed can be viewed at motioncity.com
You can use module -- code
You can use module -- code per node
http://drupal.org/project/cpn
css in a specific node
I added
#node-4 {
text-shadow:0 2px #ffffff;
}
Seems to work. Didn't try a content type.
Ah ha! Just the shove in the right direction that I needed
Thanks to this thread.
I just wanted to change the CSS within a couple of specific node as well. Got the Node ID, which should be the id selector (#) - double checked it was the case by inspecting the element on the page
Then put this in the theme's css stylesheet - This was to change the text align for p in two specific nodes:
#node-15, #node-19 p {
text-align: justify;
-moz-text-align-last: center; /* Code for Firefox */
text-align-last: center;
margin-bottom: 15px;
}
Worked like a beauty.
Seems like my web coding skills are progressing. I'm still learning and it's been a staggered approach to learning, but with consistency I'll get there and keep getting those "Ah Ha!" or "ahh, derrr, of course" moments
Drupal 8
In Drupal 7, there is a class like path-node-NID (with NID replaced by the node ID of the node being viewed) added to the <body> tag so we can easily add CSS styles to specific nodes.
Drupal 8 is missing this core D7 functionality, but now there is a module for that, its called Body node ID class
--------------
zoubi.me