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 6777933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:12:25+00:00 2026-05-26T16:12:25+00:00

I have a nice script which lets you change the background color of a

  • 0

I have a nice script which lets you change the background color of a site. As I am using LESS CSS, I’m able to adjust the color of different sections of the site. For example:

@bgcolor: #bad2e3;

body {
    background-color: @bgcolor;
}
.section {
    background-color: (darken(@bgcolor,10%);
}

When a user chooses a background color, I can simply call less.refreshStyles(); and this works fine.

My problem is I need the body text to be change dependent on the background color. For example, a dark background color requires a light body text, and vice versa.

I could code this into the CSS, but this would mean specifying a body text color for each possible background color.

Is there a function, either using the color functions available in LESS, or using jQuery, where I can detect the darkness of the background color and change the body text color if necessary?

By way of example, 0to255.com shows light/dark text dependent on the background color.

  • 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-05-26T16:12:25+00:00Added an answer on May 26, 2026 at 4:12 pm

    This returns the background color of your body:

    document.body.style.backgroundColor
    

    Edit: Sorry missunderstood the question. In this link get color contrast you have a function to detect the contrast of a color in javascript:

    function getContrastYIQ(hexcolor){
        var r = parseInt(hexcolor.substr(0,2),16);
        var g = parseInt(hexcolor.substr(2,2),16);
        var b = parseInt(hexcolor.substr(4,2),16);
        var yiq = ((r*299)+(g*587)+(b*114))/1000;
        return (yiq >= 128) ? 'light' : 'dark';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Ant script which turns my Java application into a nice Mac
I'm using Valum's AJAX uploader, which is quite nice. I have a form that
Does anyone happen to have some sort of a nice command line script they
I have a nice and lovely Django site up and running, but have noticed
Say I have a nice domain model, using (constructor) DI where needed. Now I
Let's suppose I have a valid Ant build script which packs up and prepares
I have a JQuery script which acts as a simple image rollover with a
I have the following script which I need to modify a little. Here is
I have a nice php and ajax script that uploads a photo and displays
I have an onEdit-script which calculates the value of a cell based on the

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.