controller/action specific CSS - Part 2

I wrote a previous entry about a pattern for making CSS rules specific to controllers and actions.

Unfortunately this didn’t work in IE. Here is an alternative solution, which is cross-browser compatible:


<body id="<%= controller.controller_name %>" class="action-<%= controller.action_name %>">

(I chose to prefix the action name with action, to avoid any potential namespace contamination )

Here are the new CSS rules:

body#register {} /* all actions in controller */
body#register.action-step_1 {} /* only step_1 action */

Sorry, comments are closed for this article.