Dynamically change color to lighter or darker by percentage CSS (Javascript)

后端 未结 24 1800
-上瘾入骨i
-上瘾入骨i 2020-11-28 01:12

We have a big application on the site and we have a few links which are, let\'s say blue color like the blue links on this site. Now I want to make some other links, but wit

24条回答
  •  时光说笑
    2020-11-28 01:37

    I found a PHP class that let me do this server side. I just output an inline CSS color style for whatever I need to be lighter/darker. Works great.

    http://www.barelyfitz.com/projects/csscolor/

    (note that the class uses PEAR for throwing errors, but I didn't want to include PEAR just to modify colors, so I just removed all the PEAR references)

    I turned it into a static class with static methods so I can call "lighten" & "darken" functions directly without creating a new object.

    Sample usage:

    $original_color = 'E58D8D';  
    $lighter_color = Css::lighten($original_color, .7);  
    $darker_color = Css::darken($original_color, .7);
    

提交回复
热议问题