Skip to content

Instantly share code, notes, and snippets.

@horrorchix89
Created January 10, 2021 04:32
Show Gist options
  • Select an option

  • Save horrorchix89/1c2071deb397aeb62d238e148783c342 to your computer and use it in GitHub Desktop.

Select an option

Save horrorchix89/1c2071deb397aeb62d238e148783c342 to your computer and use it in GitHub Desktop.
Sass tint/shade vs lighten/darken color functions
<h2 class="title">Tint</h2>
<ul class="color-list">
<li class="tile tile--tint"></li>
<li class="tile tile--tint"></li>
<li class="tile tile--tint"></li>
<li class="tile tile--tint"></li>
<li class="tile tile--tint"></li>
<li class="tile tile--tint"></li>
<li class="tile tile--tint"></li>
<li class="tile tile--tint"></li>
<li class="tile tile--tint"></li>
<li class="tile tile--tint"></li>
</ul>
<h2 class="title">Lighten</h2>
<ul class="color-list">
<li class="tile tile--lighten"></li>
<li class="tile tile--lighten"></li>
<li class="tile tile--lighten"></li>
<li class="tile tile--lighten"></li>
<li class="tile tile--lighten"></li>
<li class="tile tile--lighten"></li>
<li class="tile tile--lighten"></li>
<li class="tile tile--lighten"></li>
<li class="tile tile--lighten"></li>
<li class="tile tile--lighten"></li>
</ul>
<h2 class="title">Shade</h2>
<ul class="color-list">
<li class="tile tile--shade"></li>
<li class="tile tile--shade"></li>
<li class="tile tile--shade"></li>
<li class="tile tile--shade"></li>
<li class="tile tile--shade"></li>
<li class="tile tile--shade"></li>
<li class="tile tile--shade"></li>
<li class="tile tile--shade"></li>
<li class="tile tile--shade"></li>
<li class="tile tile--shade"></li>
</ul>
<h2 class="title">Darken</h2>
<ul class="color-list">
<li class="tile tile--darken"></li>
<li class="tile tile--darken"></li>
<li class="tile tile--darken"></li>
<li class="tile tile--darken"></li>
<li class="tile tile--darken"></li>
<li class="tile tile--darken"></li>
<li class="tile tile--darken"></li>
<li class="tile tile--darken"></li>
<li class="tile tile--darken"></li>
<li class="tile tile--darken"></li>
</ul>
@import "color-schemer";
@import "compass/css3";
$color: #3cdf05;
$tiles: 10;
@function tint($color, $percentage) {
@return mix(#FFF, $color, $percentage);
}
@function shade($color, $percentage) {
@return mix(#000, $color, $percentage);
}
// Return opaque color
// opaque(#fff, rgba(0, 0, 0, .5)) => #808080
@function opaque($bg, $fg) {
@return mix(rgba($fg, 1), $bg, opacity($fg) * 100);
}
@function brightness($color) {
@if type-of($color) == color {
@return ((red($color) * .299) + (green($color) * .587) + (blue($color) * .114)) / 255 * 100%;
}
@else {
@return unquote("brightness(#{$color})");
}
}
@debug midnightblue; // #191970
* {
box-sizing: border-box;
}
.title {
font: bold 2rem/1.5 "Roboto", "Helvetica Neue", Helvetica, Arial, sans-serif;
margin: 0 0 0 20px;
padding: 60px 0 0;
}
.color-list {
float: left;
display: block;
width: 100%;
}
.tile {
width: 70px;
height: 70px;
border: 1px solid transparentize(#DDD, 0.15);
border-radius: 3px;
box-shadow: 0 0 0 5px #FFF inset;
float: left;
margin: 0 0 20px 20px;
background-color: $color;
&--tint {
@for $i from 1 through $tiles {
&:nth-child(#{$i}) {
background: tint($color, 10*$i);
}
}
}
&--lighten {
@for $i from 1 through $tiles {
&:nth-child(#{$i}) {
background: lighten($color, 10*$i);
}
}
}
&--shade {
@for $i from 1 through $tiles {
&:nth-child(#{$i}) {
background: shade($color, 10*$i);
}
}
}
&--darken {
@for $i from 1 through $tiles {
&:nth-child(#{$i}) {
background: darken($color, 10*$i);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment