Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 6 of 6
Like Tree2Likes
  • 1 Post By mlseim
  • 1 Post By mlseim

Thread: Just a simple css like body { background-color: red; } will not change the background

  1. #1
    Senior Member
    Join Date
    Nov 2012
    Posts
    113
    Member #
    33949
    Liked
    2 times

    Just a simple css like body { background-color: red; } will not change the background

    Hi, my background will not change color, but when I change .navbar { } for instance, that will change, but not a simple css for body { background-color: red; }
    People that I have spoken to, said it works for them, in the theme I have, which is twentythirteen in wordpress, so I can't figure out why this is happening.

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,973
    Member #
    5580
    Liked
    760 times
    I didn't look at the CSS for that theme ...

    But I suspect they don't define the size (width) of <body>.

    body{margin:0px auto; width:100%;}

    And then, is there a way to customize the 'look' of the theme?
    Do they have a way to do that using the admin panel?

    For a simple test, you could write an inline CSS rule for <body> by modifying the header.php file.

    Locate <body>

    Make the following change:

    <body style="margin:0px auto; width:100%; background-color:red;">

    Save it and see what happens.

    It's possible that it actually is working but the <div> of the content is totally filling the body and you can't see it.

    So you would alter the <html> tag instead:

    html, body{margin:0px auto; width:100%; background-color:red;}
    spencer likes this.


  4. #3
    Senior Member
    Join Date
    Nov 2012
    Posts
    113
    Member #
    33949
    Liked
    2 times
    Where exactly do I add <body style="margin:0px auto; width:100%; background-color:red;">
    as this is the code I see in header.php: Do, I just put <body style="margin:0px auto; width:100%; background-color:red;"><?php body class(); ?>
    I dont want to break and make the site inoperable, by doing it wrong.

    <body <?php body_class(); ?>>
    <?php wp_body_open(); ?>
    <div id="page" class="hfeed site">
    <header id="masthead" class="site-header" role="banner">
    <a class="home-link" href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home">
    <h1 class="site-title"><?php bloginfo( 'name' ); ?></h1>
    <h2 class="site-description"><?php bloginfo( 'description' ); ?></h2>
    </a>

  5. #4
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,973
    Member #
    5580
    Liked
    760 times
    So your theme uses the php body_class function ... that complicates things.

    Locate the main CSS style (perhaps it's called main.css?) and edit that file.
    Add this at the bottom:

    .my-class { margin:0px auto; width:100%; background-color:red; }


    Then, change the body tag to this:

    <body <?php body-class( 'my-class' ); ?>>


    That should add your class to whatever the theme is inserting into the script.


    Otherwise, you'll be adding filters to the function located in the function.php script.

    See this:
    https://webdesign.tutsplus.com/tutor...ess--cms-21077
    spencer likes this.


  6. #5
    Senior Member
    Join Date
    Nov 2012
    Posts
    113
    Member #
    33949
    Liked
    2 times
    Thanks, I have a child theme, do I just put ..my-class { margin:0px auto; width:100%; background-color:red; } in there.
    The child theme style sheet is called style.css.
    The address for https://webdesign.tutsplus.com/tutor...ess--cms-21077, says page not found.
    Do you possibly have another link, where I could find out about this. I know what are php filter is and does, I just want to find out more, about how I can use it to get my background color to display.
    Last edited by spencer; Oct 18th, 2021 at 04:14 AM.

  7. #6
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,973
    Member #
    5580
    Liked
    760 times
    Yes.
    If you have a child theme and add your own styles to the child theme CSS it should be using the style you specify. If that doesn’t work then either your child theme is not working (configured correctly) or the main theme you are using is not following the rules.

    This whole discussion is why Wordpress can be hard to use. Wordpress assumes people will use what they provide and not want to customize.

    You’ll be constantly frustrated and discover making websites for people is way harder than you thought, and in the end, most people will never update or use their site at all. Then they’ll want you to change it some more and put in new content, which should be their job, not yours.

    Not an easy business to succeed at. I don’t mean to discourage you, but spend more time learning PHP/SQL and javascripting. Get the basic mindset for programming and Wordpress will be easier to understand.

    If you have a personal online idea you want to do (for yourself) that involves PHP … or you think it does, let me know. An example is a PHP script that automatically sends an email to your phone for some specific reason. Emails are free, text messaging is not. PHP can send email and can process incoming data from a URL or a webpage form. If you pay for a Twilio account, PHP can send and receive text messages. Or, PHP can process requests from microcontrollers connected to WiFi. Example, ESP32 or Arduino. Think of Internet of Things.
    Last edited by mlseim; Oct 18th, 2021 at 04:27 PM.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Tags for this Thread

All times are GMT -6. The time now is 03:26 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com