gradients.scss 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /**
  2. * @class Global_CSS
  3. */
  4. @import "compass/css3/images";
  5. $default-gradient: matte !default;
  6. $support-for-original-webkit-gradients: false;
  7. /**
  8. * Adds a background gradient into a specified selector.
  9. *
  10. * @include background-gradient(#444, 'glossy');
  11. *
  12. * You can also use color-stops if you want full control of the gradient:
  13. *
  14. * @include background-gradient(#444, color-stops(#333, #222, #111));
  15. *
  16. * @param {Color} $bg-color
  17. * The base color of the gradient.
  18. *
  19. * @param {String/List} [$type=$default-gradient]
  20. * The style of the gradient, one of five pre-defined options: matte, bevel, glossy, recessed, or linear:
  21. *
  22. * @include background-gradient(red, 'glossy');
  23. *
  24. * It can also accept a list of color-stop values:;
  25. *
  26. * @include background-gradient(black, color-stops(#333, #111, #000));
  27. *
  28. * Values 'flat' and 'none' will result in no gradient, just flat background-color
  29. *
  30. * @param {String} $direction
  31. * @param {Number} [$contrast=1]
  32. * The direction of the gradient.
  33. */
  34. @mixin background-gradient(
  35. $bg-color,
  36. $type: $default-gradient,
  37. $direction: top,
  38. $contrast: 1
  39. ) {
  40. $flat: $type == null or $type == none or $type == flat;
  41. @if $flat or ($bg-color == transparent) {
  42. background-color: $bg-color;
  43. @if $bg-color != null {
  44. // invoking this mixin with null, none, or flat as the $type parameter means
  45. // "no gradient" so make sure we don't inherit one via the cascade
  46. background-image: none;
  47. }
  48. }
  49. @if not ($flat or ($bg-color == transparent)) {
  50. @if type-of($type) == "list" {
  51. // Color stops provided - no $bg-color required
  52. @include background-image(linear-gradient($direction, $type));
  53. } @else if $bg-color != transparent {
  54. // Named gradients
  55. @if $bg-color == null {
  56. @warn '@background-gradient: $bg-color is required for named gradient "#{$type}"';
  57. } @else if $type == bevel {
  58. @include background-image(bevel-gradient($bg-color, $direction, $contrast));
  59. } @else if $type == glossy {
  60. @include background-image(glossy-gradient($bg-color, $direction, $contrast));
  61. } @else if $type == recessed {
  62. @include background-image(recessed-gradient($bg-color, $direction, $contrast));
  63. } @else if $type == linear {
  64. @include background-image(linear-gradient($direction, color_stops(lighten($bg-color, 5%), darken($bg-color, 10%))));
  65. } @else if $type == matte {
  66. @include background-image(matte-gradient($bg-color, $direction, $contrast));
  67. } @else {
  68. @warn '@background-gradient: invalid gradient name "#{$type}"';
  69. }
  70. }
  71. }
  72. }
  73. // These are functions so they can be combined together with background-image()// ie. @include background-image(background_noise(), glossy-gradient());
  74. @function bevel-gradient($bg-color: $base-color, $direction: top, $contrast: 1) {
  75. @return linear-gradient($direction, color_stops(
  76. lighten($bg-color, 15%),
  77. lighten($bg-color, 8%) 30%,
  78. $bg-color 65%,
  79. darken($bg-color, 6%)
  80. ));
  81. }
  82. @function glossy-gradient($bg-color: $base-color, $direction: top, $contrast: 1) {
  83. @return linear-gradient($direction, color_stops(lighten($bg-color, 15% * $contrast), lighten($bg-color, 5% * $contrast) 50%, $bg-color 51%, darken($bg-color, 5% * $contrast)));
  84. }
  85. @function recessed-gradient($bg-color: $base-color, $direction: top, $contrast: 1) {
  86. @return linear-gradient($direction, color_stops(darken($bg-color, 10% * $contrast), darken($bg-color, 5% * $contrast) 10%, $bg-color 65%, lighten($bg-color, .5% * $contrast)));
  87. }
  88. @function matte-gradient (
  89. $bg-color: $base-color,
  90. $direction: top,
  91. $contrast: 1
  92. ) {
  93. @return linear-gradient(
  94. $direction,
  95. color_stops(
  96. lighten($bg-color, 15% * $contrast),
  97. lighten($bg-color, 5% * $contrast) 3%,
  98. darken($bg-color, 5% * $contrast)
  99. )
  100. );
  101. }