Last active
December 16, 2015 02:19
-
-
Save stowball/5361657 to your computer and use it in GitHub Desktop.
Perfect CSS3 gradient rules, which seems impossible to create with Sass, Compass, Bourbon or any other strangely named thing
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
| div { | |
| background: #000; | |
| background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIHZpZXdCb3g9IjAgMCAxIDEiIHByZXNlcnZlQXNwZWN0UmF0aW89Im5vbmUiPjxsaW5lYXJHcmFkaWVudCBpZD0iZzIyOSIgZ3JhZGllbnRVbml0cz0idXNlclNwYWNlT25Vc2UiIHgxPSIwJSIgeTE9IjAlIiB4Mj0iMCUiIHkyPSIxMDAlIj48c3RvcCBzdG9wLWNvbG9yPSIjZmZmZmZmIiBvZmZzZXQ9IjAiLz48c3RvcCBzdG9wLWNvbG9yPSIjMGYwIiBvZmZzZXQ9IjAuMiIvPjxzdG9wIHN0b3AtY29sb3I9IiMwZjAiIG9mZnNldD0iMC40Ii8+PHN0b3Agc3RvcC1jb2xvcj0iIzAwMDAwMCIgb2Zmc2V0PSIxIi8+PC9saW5lYXJHcmFkaWVudD48cmVjdCB4PSIwIiB5PSIwIiB3aWR0aD0iMSIgaGVpZ2h0PSIxIiBmaWxsPSJ1cmwoI2cyMjkpIiAvPjwvc3ZnPg==); | |
| background: -moz-linear-gradient(top, #fff 0%, #0f0 20%, #0f0 40%, #000 100%); | |
| background: -webkit-linear-gradient(top, #fff 0%, #0f0 20%, #0f0 40%, #000 100%); | |
| background: linear-gradient(to bottom, #fff 0%, #0f0 20%, #0f0 40%, #000 100%); | |
| -pie-background: linear-gradient(top, #fff 0%, #0f0 20%, #0f0 40%, #000 100%); | |
| } | |
| Requirements. 1 mixin to produce: | |
| * Fallback background colour of the last node | |
| * Base64 SVG gradient for IE9 & older Opera using background-image, not background, so LT IE 9 don't get a null background | |
| * -moz, -webkit & -pie prefixes using the old syntax | |
| * Unprefixed rule using the new "to" syntax or the correct angle if deg used (newAngle = -oldAngle + 90) | |
| * Need to be able to specify the direction or angle per gradient, with default as to "top"/"to bottom" |
You can also control the support for prefixes in compass configuration:
http://compass-style.org/reference/compass/helpers/cross-browser/#prefixed
Maybe this will help a bit too
The way I think it works (in your case) would be something along the line:
Compass::BrowserSupport.add_support("linear-gradient", "webkit", "moz", "pie") and so on
Author
BTW, I have written my own solution for this which I will release soon :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Alright, doing this out of the top of my head and cannot test really right now, but this might set you in the right direction:
and be used as:
Yet you'll have to manually do the SVG then.