Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8140759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:16:21+00:00 2026-06-06T12:16:21+00:00

I have a page where the background colour can be set dynamically. In some

  • 0

I have a page where the background colour can be set dynamically. In some instances I have child divs I would like to use background-color:inherit to keep them the same colour as the body.

What I find is that when the body background colour is changed, the inherited colours aren’t consistently cascaded. It appears to be ok in Firefox but not in Chrome or IE.

In firefox it consistently changes both elements. In chrome and IE the results seem varied, but if you click on the colour the background already is (e.g. everything is blue, click on the “blue” button) and then another colour, it seems to consistently break.

(I do realise the inherited colour isn’t needed in this example, however I’m just trying to demo the issue in as little code as possible.)

http://jsfiddle.net/48HBe/2/

If this were one browser only then I would suspect this was a possible browser issue, but as it seems to affect Chrome and IE I’m wondering if I’m expecting something unreasonable from the browser’s rendering and whether I should be using an alternative approach?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T12:16:23+00:00Added an answer on June 6, 2026 at 12:16 pm

    Your code seems to work fine in Chrome, anyway if the problem is related to IE, I would try a different approach. Instead of changing a single css property, just try to change the class name of body element, like in this example fiddle: http://jsfiddle.net/48HBe/3/

    the css thus becomes

    body, body.blue { background-color:blue; }
    body.green { background-color:green; }
    body.red { background-color:red; }
    

    and the js code is simply

    ...
    var b = document.body;
    $("#RedButton").click(function()   { b.className = 'red';   });                  
    $("#GreenButton").click(function() { b.className = 'green'; });                  
    $("#BlueButton").click(function()  { b.className = 'blue';  });
    

    doing so you have a better separation between logic and presentation and you could change more style properties inside the css (and not inside js code)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page where the body is set to a background colour. I
I have a page like below; <style type=text/css> #div1 { height: 100px; background-color: #CCCCCC;
i have this html page: Code: <html> <!-- ... -->or explicity set the background-color
I have the following HTML page and the background color for the content is
I have this JSF page: <div id=settingsdiv style=width:350px; height:400px; position:absolute; background-color:r; top:20px; left:1px> <h:form>
I'd like to have my background page watch the URL and call chrome.tabs.executeScript on
I have set a background image for a mobile page with mobile.jquery. So far
I have got a table, on a page: <table border=0 width=320px height=480px style=background-color: black;>
I have a page that uses a background image to do rounded corners, and
I have just created an HTML5 page with a background image in the top

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.