Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm using SASS for some styling. I have a base colour, and I want all other colours to change relative to the base colour. I have set the colours up how I want them but the colours are hard coded and not calculated from the base colour.

Is there a tool that quickly generates SASS colour functions for the difference between two colours? There is this tool: http://sassme.arc90.com/ - but it only allows me to generate the output colour with sliders, instead of setting output colour myself and it generate the function.

Hope this makes sense.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
446 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can check out the following resource:

Building Color Palettes with SASS

Basically, here's the meat of it:

@function color-diff($a, $b) {
  $sat: saturation($a) - saturation($b);
  $lig: lightness($a) - lightness($b);
  $fn-sat: if($sat > 0, 'desaturate', 'saturate');
  $fn-lig: if($lig > 0, 'darken', 'lighten');
 
  @return (
    adjust-hue: -(hue($a) - hue($b)),
    #{$fn-sat}: abs($sat),
    #{$fn-lig}: abs($lig)
  );
}

You want to do this with a function in SASS (or a parameterized mixin in LESS), and you can see the structure of one above.

Hope this helps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...