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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:59:30+00:00 2026-06-17T17:59:30+00:00

I’d like to be able to be able to calculate the second hex color

  • 0

I’d like to be able to be able to calculate the second hex color of a button background gradient based on the first (see sample below).

So I would get the first color via a color picker from the user and get that using Javascript (e.g. #ededed in the sample below). Based on the first color, I would like to use JS to calculate an offset which generates the second color and the gradient effect (#dfdfdf in the sample below). The color shift would always be the same, just the input and output hex colors would differ.

Is there a formular or function I could use? thanks!

background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #ededed), color-stop(1, #dfdfdf) );
  • 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-17T17:59:32+00:00Added an answer on June 17, 2026 at 5:59 pm

    Just so you know, you’re using the “old” format for -webkit-gradient. You should update to using this instead:

    -webkit-linear-gradient(top, #ededed 5%, #dfdfdf)
    

    Now, on to the actual problem, you haven’t specified how the second colour should be calculated. I’ll assue you want it a shade lighter, considering the example you gave. In this case, you can do this:

    var color = "#ededed";
    var components = [
        (255-(255-parseInt(color.substr(1,2),16))/2).toString(16),
        (255-(255-parseInt(color.substr(3,2),16))/2).toString(16),
        (255-(255-parseInt(color.substr(5,2),16))/2).toString(16)
    ];
    if(components[0].length < 2) components[0] = "0"+components[0];
    if(components[1].length < 2) components[1] = "0"+components[1];
    if(components[2].length < 2) components[2] = "0"+components[2];
    var out = "#"+components[0]+components[1]+components[2];
    

    This will give you the colour that is halfway between the source colour and pure white (effectively overlaying a 50%-opacity white over it). To get a darker shade, just remove the 255-(255- bit and the corresponding ).

    EDIT: On second thoughts, just use a solid background with a transparent gradient:

    background:#ededed -webkit-linear-gradient(top,rgba(255,255,255,0),rgba(255,255,255,1));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables with like below codes: Table: Accounts id | username |
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I would like to run a str_replace or preg_replace which looks for certain words
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.