1

Anyone know how to have one CSS stylesheet for logged in users and another for anonymous users?

2
  • Can you give more information on what you want to look different for the different roles? The best solution will probably depend on what you want to change per user. For example, if it is a large amount of things it might make sense to have multiple themes but if it's only a very small amount of things it may just be using a body class to distinguish between logged in or out.
    – rooby
    May 29, 2015 at 2:11
  • @rooby certainly. thanks for your reply. I have a 'sharing' bar on a specific node type that I've absolutely positioned on the page. However, it gets out of position if a user is logged in because of all the admin UI stuff at the top of the page. So I want this particular <div> to have a different value for 'top' if a user is logged in.
    – Sage
    May 29, 2015 at 2:15

1 Answer 1

4

The template_preprocess_html() preprocess function adds a 'logged-in' or 'not-logged-in' class to the classes array. These classes get printed in the html.tpl.php template on the body tag.

So you should be able to target anything in your css for logged in or logged out users by using those classes. For example:

.sharing-block {
  top: 0px;
}
.logged-in .sharing-block {
  top: 25px;
}

Something like that should work without needing to worry about conditionally applied stylesheets or anything like that.

0

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.