1

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;
}
1
  • body.marinelli.logged-in {background: blah bla}
    – AKS
    May 28, 2014 at 16:21

5 Answers 5

4

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;
}
1
  • 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, 2014 at 23:43
0

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

1
  • 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, 2014 at 5:20
0

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 .

2
  • 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, 2014 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
    – Yuseferi
    May 27, 2014 at 5:38
0

You can use

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

in the main stylesheet of the Marinelli template

-1

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 */
}
3
  • 1
    And what is different in your answer than the other answers? You are saying just the same thing the other answers say.
    – Elin Y.
    Jun 1, 2014 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. Oct 1, 2014 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.
    – Elin Y.
    Oct 2, 2014 at 5:17

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.