• Resolved octocore

    (@octocore)


    Hello, and thanks for looking.

    I have a simple problem. I’d like to be able to change the background color depending on which page I’m on. Would the body_class function be a good way of doing this, and if so, how do I know which class to use?

    For example, would I use CSS like:

    #body .home {
    background-color:#0033CC;
    }

    to do this? (this didn’t work by the way..), or is there a better solution?

    Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • the right style to use would be:

    body.home {}

    to know the class(es) look at the html code in the browser and look for something like:
    <body class="home blog logged-in">
    or
    <body class="single postid-1">

    Thread Starter octocore

    (@octocore)

    I see what you’re saying about finding the class in the source code, but I can’t seem to get the background color to change.

    here’s my site:
    https://www.louiesolomon.com

    I’ve tried using a few different CSS lines, none of which seem to work when I add a background color attribute:

    body.home
    body.home.blog
    body.blog
    body.page-id-2

    Any idea what I’m doing wrong? Thanks again.

    body.home would be correct, just try forcing the style..

    body.home { background-color:#000!important; }
    Thread Starter octocore

    (@octocore)

    Thanks for the reply. I figured out the problem. In the theme I was using, the body class code was written:

    <body class=<?php body_class(); ?>>

    instead of the proper

    <body <?php body_class(); ?>>

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘body_class – how do I know which class I’m in?’ is closed to new replies.