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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

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.

            
              <!--
    Demo for this article:
    http://blustemy.io/color-helper-functions-in-sass/
-->

<h1>tint(#1098ad, 0% … 100%)</h1>
<ul class="colors tint">
    <li>0%</li>
    <li>25%</li>
    <li>50%</li>
    <li>75%</li>
    <li>100%</li>
</ul>

<h1>shade(#1098ad, 0% … 100%)</h1>
<ul class="colors shade">
    <li>0%</li>
    <li>25%</li>
    <li>50%</li>
    <li>75%</li>
    <li>100%</li>
</ul>

<h1>white(0% … 100%)</h1>
<ul class="colors white">
    <li>white(0%)</li>
    <li>white(25%)</li>
    <li>white(50%)</li>
    <li>white(75%)</li>
    <li>white(100%)</li>
</ul>

<h1>black(0% … 100%)</h1>
<ul class="colors black">
    <li>black(0%)</li>
    <li>black(25%)</li>
    <li>black(50%)</li>
    <li>black(75%)</li>
    <li>black(100%)</li>
</ul>

<h1>Example</h1>
<a href="#" class="button">This is a button link</a>

            
          
!
            
              /*
    Demo for this article:
    http://blustemy.io/color-helper-functions-in-sass/
*/

// Return a lighter color
// 0% is the same color, 100% is white
@function tint($color, $percent: 0%, $alpha: 1) {
    @return rgba(mix(white, $color, $percent), $alpha);
}

// Return a darker color
// 0% is the same color, 100% is black
@function shade($color, $percent: 0%, $alpha: 1) {
    @return rgba(mix(black, $color, $percent), $alpha);
}

// Return an intensity of white
// 0% is black, 50% is a middle gray, 100% is white
@function white($percent: 100%, $alpha: 1) {
    @return rgba(mix(white, black, $percent), $alpha);
}

// Return an intensity of black
// 0% is white, 50% is a middle gray, 100% is black
@function black($percent: 100%, $alpha: 1) {
    @return rgba(mix(black, white, $percent), $alpha);
}

// Demo
$color-example: #1098ad;

body {
    font-family: "Arial", sans-serif;
    background: black(7%);
}

h1 {
    font-size: 1rem;
}

.colors {
    list-style: none;
    margin: 0 0 2em 0;
    padding: 0;
    
    &::before {
        content: "";
        display: block;
        margin-bottom: .5em;
    }

    > li {
        display: inline-block;
        font-size: .85em;
        text-align: center;

        &::before {
            content: "";
            display: block;
            width: 7em;
            height: 4em;
            margin-bottom: .5em;
        }
    }
}

.tint {
    @for $i from 0 through 4 {
        > li:nth-child(#{$i + 1})::before {
            background: tint($color-example, percentage($i / 4));
        }
    }
}

.shade {
    @for $i from 0 through 4 {
        > li:nth-child(#{$i + 1})::before {
            background: shade($color-example, percentage($i / 4));
        }
    }
}

.white {
    @for $i from 0 through 4 {
        > li:nth-child(#{$i + 1})::before {
            background: white(percentage($i / 4));
        }
    }
}

.black {
    @for $i from 0 through 4 {
        > li:nth-child(#{$i + 1})::before {
            background: black(percentage($i / 4));
        }
    }
}

.button {
    display: inline-block;
    padding: .5em 1.25em;
    color: white;
    background: linear-gradient(tint($color-example, 20%), $color-example);
    background-color: $color-example; // flat color on older browsers
    border: .08em solid shade($color-example, 8%);
    border-radius: .1em;
    text-decoration: none;
    box-shadow: 0 .1em .5em black(80%, .2);
    transition: border-color .3s;
    
    &:hover {
        // Darker border on hover.
        border-color: shade($color-example, 50%);
    }
}

            
          
!
999px
Loading ..................

Console