cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              @import "compass/css3";

// Ever wanted to know what would be the color operations to apply to a color 
// in order to find a second color, just out of curiosity?
// Like, "how to programmatically go from #BADA55 to #B0BCA7"?
// --------------------------------------------------------------------------------
// @param (color) $a: first color
// @param (color) $b: second color
// --------------------------------------------------------------------------------
// @return (map) returns the color operations to do in order to find $b from $a
//   where keys are the color functions to apply
//   and values are the values to pass to these functions
 
@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)
  );
}
 
// Apply differences returned from `color-diff` function to a color
// In order to retrieve the second color
// --------------------------------------------------------------------------------
// @param (color) $color: color to transform
// @param (map) $diff: diff map
// --------------------------------------------------------------------------------
// @return (color) transformed color
 
@function apply-diff($color, $diff) {
  // We call the $key (function), 
  // passing the $color and the $value as parameters
  // e.g. `call(adjust-hue, #BADA55, 42)`
  @each $key, $value in $diff {
    $color: call($key, $color, $value);
  }
  @return $color;
}
 
// --------------------------------------------------------------------------------
// Example
// --------------------------------------------------------------------------------
 
// Pick two random colors
$a: #BADA55;
$b: #B0BCA7;
 
// Calculate the diff map between those 2
$diff: color-diff($a, $b);
// This is a map looking like this:
// $diff: (
//   adjust-hue: 42,
//   saturation: 13.37%,
//   lightness: 1.5%
// );
 
// Apply the diff to one of the two colors to find the second one
$c: apply-diff($a, $diff); 
 
// Is everything okay?
sass {
  a: $a;
  b: $b;
  c: $c; // $b == $c, awesome!
}
 
// Visual representation if you prefer
// left part is $a
// middle part is $b
// third part is $c, generated from $a
html {
  background: -webkit-linear-gradient(left, $a 33%, $b 33%, $b 66%, $c 66%);
  height: 100%;
}
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console