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

  • Home
  • SEARCH
  • 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 8662989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:52:15+00:00 2026-06-12T16:52:15+00:00

I have a <p> element inside a <div> . There are two possible colors

  • 0

I have a <p> element inside a <div>. There are two possible colors for the paragraph text: white or black. This color is chosen randomly at run-time. The background div’s color is randomly chosen at run-time among 16 million colors. Because both of these processes are random, sometimes similar colors end up together and the paragraph text is very hard to see or can’t be seen at all.

Is there an algorithm out there that compares two colors to each other and returns, in percentage notation, how one would look on top of another?

This question was asking how similar two colors are: Color Logic Algorithm

I want to know how one looks when layered on another. For example, according to the function defined in the above post, yellow and white are not similar colors, but when white is written on yellow, the text can’t be seen easily.

  • 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-12T16:52:16+00:00Added an answer on June 12, 2026 at 4:52 pm

    This website should be of help:

    http://24ways.org/2010/calculating-color-contrast

    according to it, use this function to determine whether to use black or white on the bg color:

    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) ? 'black' : 'white';
    }
    

    Of course, you will have to convert the colors to their hex values to use them.

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

Sidebar

Related Questions

I have an input element inside a div element: ... <div id=calculator-container> <input type=text
I have a paragraph element inside a div. The div has an opacity of
i want to have an element inside a div set to height 100%. The
I have an outside div, inside this is a lot of P elements and
I have an html td element with text inside. I want it so you
if i have this code in jquery: var parentDiv = $(this).parent('.copyInstance'); inside this div
I have got ul-li list in which there is a span element inside all
New to css. I have a div element, in which there are multiple links
Possible Duplicate: How to select an element by class inside “this” in Jquery I'm
I have two HTML elements inside a div. I want to display them in

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.