Created
September 23, 2016 12:34
-
-
Save zizu-kun/96e5d8c01f28120a3b9dfe2d5d01da69 to your computer and use it in GitHub Desktop.
SASS:Gradient Mixin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @mixin linear-gradient($fromColor, $toColor) { | |
| background-color: $toColor; /* Fallback Color */ | |
| background-image: -webkit-gradient(linear, left top, left bottom, from($fromColor), to($toColor)); /* Saf4+, Chrome */ | |
| background-image: -webkit-linear-gradient(top, $fromColor, $toColor); /* Chrome 10+, Saf5.1+, iOS 5+ */ | |
| background-image: -moz-linear-gradient(top, $fromColor, $toColor); /* FF3.6 */ | |
| background-image: -ms-linear-gradient(top, $fromColor, $toColor); /* IE10 */ | |
| background-image: -o-linear-gradient(top, $fromColor, $toColor); /* Opera 11.10+ */ | |
| background-image: linear-gradient(top, $fromColor, $toColor); | |
| filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,StartColorStr='$fromColor', EndColorStr='$toColor'); | |
| } | |
| /* Usage - Stick into the top of your SCSS sheet and @include where needed for cross browser linear gradients. | |
| .class { | |
| @include linear-gradient(#color, $color); | |
| } | |
| Can pass Hex values or indeed a variable color if required. | |
| Usage example; | |
| ------------- | |
| $myColor: red; // not required unless using variable. | |
| .item { | |
| @include linear-gradient(#BADA55, $myColor); | |
| } | |
| ------------- | |
| IE9 Support (idea courtesy of http://www.colorzilla.com/gradient-editor/ ) | |
| Support for full multi-stop gradients with IE9 (using SVG). | |
| Add a "gradient" class to all your elements that have a gradient, and add the following override to your HTML to complete the IE9 support: | |
| <!--[if gte IE 9]> | |
| <style type="text/css"> | |
| .gradient { | |
| filter: none; | |
| } | |
| </style> | |
| <![endif]--> | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment