Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I'm pleased with my body background for my site; it looks great when not logged in. But when a user is logged in I need a different one. I need to specify a slightly different background because of the fact that my Marinelli-based D7 site's custom body background (2 horizontal bands of green and black) stays in position but all content moves down almost 100px due to the administrative menu at the top.

An authenticated user would not be able to see the navbar due to this color change (green words on a now green background).

Can I specify an alternate background for authenticated users vs. visitors? Or perhaps better: Is there a way to specify that the body background should move down when the user logs in and all the admin menus show up at the top?

Here's my present CSS for body:

body.marinelli{
    background: #fff url(../img/backgrounds/body-background.jpg);
    background-repeat:repeat-x;
}
share|improve this question
    
body.marinelli.logged-in {background: blah bla} –  AyeshK May 28 at 16:21

5 Answers 5

up vote 4 down vote accepted

I think your solution would be the class "logged-in" and the CSS property "background-position" to move the background image down 100px for logged-in users:

body {
  background: #fff url(../img/backgrounds/body-background.jpg);
  background-repeat: repeat-x;
}

body.logged-in {
  background-position: 0 100px;
}
share|improve this answer
    
This answer from YAN seems to be the best and easiest. Thanks. I've already used it and it works. ended up using 70 px to drop down the background for the current set of admin tools that show up for me, I'll adapt later for the other users that don't get all the admin tools. –  Dave N Jun 3 at 23:43

I have another plan, you can do it in html.tpl.php or in 'page.tpl.php'

do something like this

<?php  global $user; 
       if($user->uid){
      $bodyclass='class-one' ;
     }
     else {
      $bodyclass='class-two' ;
   }
?>
<body  class ="<?php print $bodyclass;" ?>" >

make sure after change tpl file clear drupal cache .

share|improve this answer
    
Thanks for the advice. Question: I'm assuming that after I add this to page.tpl.php or html.tpl.php template that I would then see TWO body classes in the layout.css, or where...? –  Dave N May 27 at 5:20
    
no, you just see one , If you are login user the body class will be class-one if you are not logged in body has class class-two , there is only one class but it get different class in login /logout manner –  zhilevan May 27 at 5:38

you can override “logged-in” class,because it is definded in function template_preprocess_html

share|improve this answer
    
Thanks for the advice. I'm wondering how do I override the "logged in" class that's defined in template_preprocess_html. –  Dave N May 27 at 5:20

You can use

body.logged-in{
       /* background css */
}

in the main stylesheet of the Marinelli template

share|improve this answer

Drupal adds the logged-in class to the body if the user is logged in.

you can write your css like this

body.logged-in {
  /* add custom css here */
}
share|improve this answer
1  
And what is different in your answer than the other answers? You are saying just the same thing the other answers say. –  Елин Й. Jun 1 at 9:54
    
I answered to that question because I always use that class, no matter what the other answers are, I think it is good to answer questions even if these are already answered. will you consider changing your DOWN vote. –  Mohammad AlQanneh Oct 1 at 18:58
    
No, because the other answer, this, is exactly the same as yours and it was posted several days before your answer. It is good to answer questions even if these are already answered, if your answer is a different approach. –  Елин Й. Oct 2 at 5:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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