Grow your CSS skills. Land your dream job.

Apply background image just on homepage [WP]

  • # January 21, 2013 at 8:44 am

    I’m using a wordpress theme and I want to apply a background image to a div just on homepage.

    How can I do this ?

    # January 21, 2013 at 8:52 am

    Depending on which page you are on, the body will have different classes, assuming your WordPress Theme calls the function body_class.

    The homepage has the class “home”, so you can use that to target the div, since my understanding of your question means that you don’t have other ways to differentiate this div from others.

    # January 21, 2013 at 7:45 pm

    Thank you for your suggestion!
    And I assume I have to write a php funtction like “if body has homepage class apply that css property”
    Can you help me with this ?

    # January 21, 2013 at 8:26 pm

    .home .yourdivclassorid { background: #fff url(yourimg.png) no-repeat top center; }

    as an example

    # January 22, 2013 at 7:03 am

    What Wolfcry wrote.

    The style should go in the CSS, not in the PHP.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".