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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:42:03+00:00 2026-05-16T00:42:03+00:00

I’m trying to figure out how to write a function that programmatically retrieves a

  • 0

I’m trying to figure out how to write a function that programmatically retrieves a background-color css attribute and creates two outputs (one slightly darker than the background-color, one slightly lighter).

The idea is being able to generate a very basic linear gradient from a single color selection.

Anyone have any ideas?

  • 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-16T00:42:03+00:00Added an answer on May 16, 2026 at 12:42 am

    To scale a color correctly, you have to multiply each RGB value by a proportion. E.g., if your color is #00417b and you want a color that is 125% lighter color then you have to do this:

    var dark = {r: 0, g: 65, b: 123};
    var light = {r: Math.round(Math.min(dark[r]*1.25, 255)),
                 g: Math.round(Math.min(dark[g]*1.25, 255)),
                 b: Math.round(Math.min(dark[b]*1.25, 255))};
    

    Compare the result for yourself: dark is #00417b, and light is #00519A, although it’s perfectly valid CSS to describe them as rgb(0, 65, 123) and rgb(0, 81, 154) and probably easier too. By scaling colors in this way they will appear to be at the same level of saturation, something that simply adding or subtracting numbers will not achieve.

    Be aware that since values are clamped at [0, 255], if you keep shifting colors, then feeding them back into this process, you can destroy information about the proportion of red, green and blue in the source color. For this reason, keep the original color saved and try to use that as your input each time.

    Since your question asked specifically about gradients though, this is how you would go between two color values:

    // Suppose you have a container which is X pixels high and you want to insert a 1-pixel tall
    // element at each pixel, going vertically
    
    var min = Math.min;
    var max = Math.max;
    var round = Math.round;
    
    function get_color_for_height(startColor, endColor, height, row) {
      var scale = row/height;
      var r = startColor[red] + scale*(endColor[red] - startColor[red]);
      var b = startColor[blue] + scale*(endColor[blue] - startColor[blue]);
      var g = startColor[green] + scale*(endColor[green] - startColor[green]);
    
      return {
        r: round(min(255, max(0, r))),
        g: round(min(255, max(0, g))),
        b: round(min(255, max(0, b)))
      }
    }
    
    
    // some psuedo-code using an imaginary framework
    for(var h = 0; h < height; h++) {
      var div = new Element('div');
      div.height = 1;
      div.backgroundColor = get_color_for_height(start, end, height, h);
      container.insert('top', div);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 495k
  • Answers 495k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You are deleting the item with the KEY being equal… May 16, 2026 at 11:13 am
  • Editorial Team
    Editorial Team added an answer This looks like a job for ... Trigonometry-man. Consider the… May 16, 2026 at 11:13 am
  • Editorial Team
    Editorial Team added an answer I think your best option would be to do: checked… May 16, 2026 at 11:13 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and

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.