Miguel Rodríguez does effective software development.

Using CSS classes to theme/customize Drupal without coding

Have I told you it Have I told you there are some Drupal modules which can change styles visually through CSS this without coding?is really important to specify styles with CSS classes in order to reuse the code?, Have I told you there are a lot of Drupal modules which have the capability to set CSS classes?, as you may know, CSS is used to define the visual styles in a webpage, CSS can assign those styles whether to specific elements, by using ID, or to groups of elements, by using Classes, for reusability matter (actually there are a lot of concepts and principles which encourage to keep things reusable and avoid redundancy such as DRY [Don't Repeat Yourself]), if is there a style which can be implemented somewhere else, you should define that style with a Class, doing this you may implement these styles easier, although you may think that you still have to code the changes, that is only theoretically.
There are phases in the Drupal theming process that do not require the intervention of any IT professional (programmer, developer, analyst/programmer, ..., however you want to call it), modules such as Panels and Views let the user create layouts visually, some of these modules let assign CSS classes visually as well, so the user may change the content, the layout and all the styles within it, for example, by the time I wrote this article, the theme that I made had a couple of CSS Classes which can be used to highlight pieces of text, so if I ever want to highlight a pieces of text with my editor (CKeditor), I just have to add the classes "messages highlight" (actually, those CSS Classes comes with Drupal by default, I just customized them) and the text would look highlighted according to the design of the theme.
CSS classes on Drupal example
There are some Drupal modules which lets the user change the content and the layout visually, even the CSS classes, this lets the user change/set the style of the whole content. 
This would save time and money, as well as relieve the IT professional of performing some tasks, let us see which of all those modules support this capability and how they let it use it.


The following paragraphs will only refer to Views 3
This module is one of the most used Drupal modules, it has a lot of capabilities, this also includes CSS classes handling along with HTML container options that let you change the appearance of the output, Views can let you set CSS classes in the container of the View itself, each row and field, using this feature you can format the whole result of the query.
There are some things that you can do, first, you can set CSS classes to the View container to change the appearance globally, this is pretty basic but useful too, second, you can set CSS classes to each row/field (you can use it along with the  View container's CSS classes), this is used for complex structures that needs multiple identified elements, it is sometimes used along with Views theming (a template "theme hook" suggestion implementation for Views) to implement external libraries and website widgets.
View container's CSS class
You can add a CSS class to the whole View, whether to set or to trigger a style.
The CSS class field for the View container is pretty simple to see, it is located in the advance menu of the View, however, in order to set a CSS class to the rows, it is necessary that you set the "unformatted list" style to the rows, and then set the row container with a custom CSS class, almost the same happens with the fields, it is necessary that you set the "field" style to the fields and set the container with a custom CSS class.
Views field's CSS classes
Views fields and rows can have custom CSS classes too.


The following paragraphs will only refer to Panels 3
I should not even say this module is widely used (you should already know it), Panels has the capability to let the user create layouts visually, the user can set the width, the title, the content (obvious) and CSS properties of each pane (a pane is an arrangeable representation of a node in the panel) this includes CSS classes, you can also add CSS properties to each region and the panel container itself, as long as you know the CSS classes, this let create complex layout through the UI without even know how to code.
Panels general settings - CSS classes
Panels pane's CSS classes
Panel panes (a representation of nodes in the panels) can also have custom CSS classes.
Setting CSS classes to the panes is pretty simple, you just have to go to the "CSS properties" option in its menu and add the classes needed, setting CSS classes to the panel container is also simple, in the general section you can find the "CSS classes" field to do this, however, unlike the "panes" and the panel container, the regions (the container of the panes) are not that simple to customize, in order to set the classes to the regions in Panels (module), you must use a flexible layout customized with the layout builder, the rest of the layouts can not be customized (at least this way), doing this, you can set any CSS class to any region.


The following paragraphs will only refer to CKeditor 3
This is a pretty good web text editor, it has a lot of capabilities, the most interesting about it is that it can create customized DIVs and show the blocks (html elements) visually, letting you edit the properties for the created DIVs, with this you can customize the text in any way you want, you can create a custom block with a specific CSS class giving a special look to a piece of the text.
CKeditor - DIV Container's CSS classes
Even any piece of text in CKeditor can have CSS classes.
The procedure to create a block was described before already, but first make sure the field supports full HTML inputs, then hit the "show blocks" button, select the content for the new block (just hold the mouse button and select the text), hit the "create DIV container" button and fill the "Stylesheet Classes" field with the CSS Classes needed.


The following paragraphs will only refer to Context 3 - Beta 6
This is a great module, it can let you change the blocks, menus, other modules behavior, and the properties of the webpage being accessed, it can only let change the properties of the webpage in general, not the property of any block or menu, but this is still pretty useful, perhaps you can trigger a specific style, or change the background of the webpage (if you can), this is something that may be used efficiently.
Context - Theme HTML's CSS classes
You can set a reaction (with context) that changes the website by using CSS classes.
Using CSS classes with Context is pretty simple, just set some conditions (path, language, node type, ...), make sure whether you want all the conditions to be true or not, add the "Theme HTML" reaction and set the necessary CSS classes, although this is a pretty simple change, you can set a style which changes when it is inside an element with an specific CSS class, with this you can even change the appearance of the whole webpage.


The following paragraphs will only refer to Omega 3
In my humble opinion, it is the best base theme available for Drupal, Omega can change the layout of the website visually, its layout is divided into sections, zones and regions that you can arrange as you need, you can even change the properties of every region and zone, including (of course) the CSS classes, with other modules such as Delta and Context, you can change the layout of different webpages depending on the conditions (previously set by the user).
Omega zones' CSS Classes
The Omega zones can have CSS Classes.
Omega regions' CSS classes
The Omega regions can also have CSS classes.
The CSS classes can be set in the "Zone and region configuration" section in the settings of the Omega subtheme, select the region or zone to change and change its properties as needed, Delta can save this configuration in order to load it in other occasion, there are some other modules that can use these data, Context is one of them, you can specify a reaction (with Delta) that changes the webpage if some conditions are met.
Context - using Delta saved data as a Context Reaction.
You can use Delta saved data as a Context Reaction.

About me

About the author
Miguel Rodríguez is a freelance developer from Caracas - Venezuela. He is a persistent and goal-oriented person who tries to make the best use of the resources. He is positive, proactive and motivated enough to set a goal with the intention to fulfill it. Find more about him .