mixins.scss 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //
  2. // Mixins
  3. // --------------------------------------------------
  4. // General
  5. // --------------------------------------------------
  6. // Utilities
  7. // -------------------------
  8. // Clearfix
  9. // Source: http://nicolasgallagher.com/micro-clearfix-hack/
  10. //
  11. // For modern browsers
  12. // 1. The space content is one way to avoid an Opera bug when the
  13. // contenteditable attribute is included anywhere else in the document.
  14. // Otherwise it causes space to appear at the top and bottom of elements
  15. // that are clearfixed.
  16. // 2. The use of `table` rather than `block` is only necessary if using
  17. // `:before` to contain the top-margins of child elements.
  18. @mixin clearfix() {
  19. &:before,
  20. &:after {
  21. display: table; // 2
  22. content: " "; // 1
  23. }
  24. &:after {
  25. clear: both;
  26. }
  27. }
  28. // Box shadow
  29. @mixin box-shadow($shadow...) {
  30. -webkit-box-shadow: $shadow;
  31. box-shadow: $shadow;
  32. }
  33. // Gradients
  34. @mixin linear-gradient($color-from, $color-to) {
  35. background-color: $color-from; // Old browsers
  36. background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%,$color-from), color-stop(100%,$color-to)); // Chrome, Safari4+
  37. background-image: -webkit-linear-gradient(top, $color-from 0%, $color-to 100%); // Chrome10+, Safari5.1+
  38. background-image: -moz-linear-gradient(top, $color-from 0%, $color-to 100%); // FF3.6+
  39. background-image: -ms-linear-gradient(top, $color-from 0%, $color-to 100%); // IE10+
  40. background-image: -o-linear-gradient(top, $color-from 0%, $color-to 100%); // Opera 11.10+
  41. background-image: linear-gradient(to bottom, $color-from 0%, $color-to 100%); // W3C
  42. filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#{$color-from}', endColorstr='#{$color-to}', GradientType=0 ); // IE6-9
  43. }
  44. @mixin directional-gradient($color-from, $color-to, $deg: 45deg) {
  45. background-color: $color-from; // Old browsers
  46. background-image: -webkit-gradient(linear, left bottom, right top, color-stop(0%,$color-from), color-stop(100%,$color-to)); // Chrome, Safari4+
  47. background-image: -webkit-linear-gradient(45deg, $color-from 0%, $color-to 100%); // Chrome10+, Safari5.1+
  48. background-image: -moz-linear-gradient(45deg, $color-from 0%, $color-to 100%); // FF3.6+
  49. background-image: -ms-linear-gradient(45deg, $color-from 0%, $color-to 100%); // IE10+
  50. background-image: -o-linear-gradient(45deg, $color-from 0%, $color-to 100%); // Opera 11.10+
  51. background-image: linear-gradient(45deg, $color-from 0%, $color-to 100%); // W3C
  52. filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#{$color-from}', endColorstr='#{$color-to}', GradientType=1 ); // IE6-9
  53. }
  54. // Transforms
  55. // --------------------------------------------------
  56. @mixin transform($transform...) {
  57. -webkit-transform: $transform;
  58. -ms-transform: $transform;
  59. transform: $transform;
  60. }
  61. // Transitions
  62. // --------------------------------------------------
  63. @mixin transition($transition...) {
  64. -webkit-transition: $transition;
  65. -moz-transition: $transition;
  66. transition: $transition;
  67. }
  68. @mixin transition-property($property...) {
  69. -webkit-transition-property: $property;
  70. -moz-transition-property: $property;
  71. transition-property: $property;
  72. }
  73. @mixin transition-duration($duration...) {
  74. -webkit-transition-duration: $duration;
  75. -moz-transition-duration: $duration;
  76. transition-duration: $duration;
  77. }
  78. @mixin transition-timing-function($function...) {
  79. -webkit-transition-timing-function: $function;
  80. -moz-transition-timing-function: $function;
  81. transition-timing-function: $function;
  82. }
  83. // Animations
  84. // --------------------------------------------------
  85. @mixin animation-name($name) {
  86. -webkit-animation-name: $name;
  87. -moz-animation-name: $name;
  88. animation-name: $name;
  89. }
  90. @mixin animation-duration($duration) {
  91. -webkit-animation-duration: $duration;
  92. -moz-animation-duration: $duration;
  93. animation-duration: $duration;
  94. }
  95. @mixin animation-direction($direction) {
  96. -webkit-animation-direction: $direction;
  97. -moz-animation-direction: $direction;
  98. animation-direction: $direction;
  99. }
  100. // Misc
  101. // --------------------------------------------------
  102. @mixin hairline($type, $color, $offset) {
  103. @if $type == single {
  104. background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100%' height='1'><rect fill='#{$color}' x='0' y='0' width='100%' height='0.5'/></svg>");
  105. background-position: $offset 100%;
  106. } @else if $type == double {
  107. background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100%' height='1'><rect fill='#{$color}' x='0' y='0' width='100%' height='0.5'/></svg>"),
  108. url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100%' height='1'><rect fill='#{$color}' x='0' y='0' width='100%' height='0.5'/></svg>");
  109. background-position: $offset 100%, $offset 0;
  110. }
  111. background-repeat: no-repeat;
  112. }