Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SASS calculate HSL Difference between 2 colours

Tags:

css

sass

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.

like image 342
Wasim Avatar asked Oct 27 '25 08:10

Wasim


1 Answers

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.

like image 198
Josh Burgess Avatar answered Oct 30 '25 00:10

Josh Burgess



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!