mixins.scss 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. /* ==========================================================================
  2. Utility mixins
  3. ========================================================================== */
  4. /*
  5. Clearfix
  6. For clearing floats like a boss h5bp.com/q
  7. ========================================================================== */
  8. @mixin clearfix {
  9. *zoom: 1;
  10. &:before,
  11. &:after {
  12. display: table;
  13. content: "";
  14. /* Fixes Opera/contenteditable bug: */
  15. /* http://nicolasgallagher.com/micro-clearfix-hack/#comment-36952 */
  16. line-height: 0;
  17. }
  18. &:after {
  19. clear: both;
  20. }
  21. }
  22. /*
  23. Webkit-style focus
  24. ========================================================================== */
  25. @mixin tab-focus() {
  26. /* Default */
  27. outline: thin dotted #333;
  28. /* Webkit */
  29. outline: 5px auto -webkit-focus-ring-color;
  30. outline-offset: -2px;
  31. }
  32. /*
  33. Center-align a block level element
  34. ========================================================================== */
  35. @mixin center-block() {
  36. display: block;
  37. margin-left: auto;
  38. margin-right: auto;
  39. }
  40. /* ==========================================================================
  41. Typography related mixins
  42. ========================================================================== */
  43. /*
  44. Maintains vertical rhythm by setting a font-sizes proportional to
  45. line-height and bottom margin
  46. example: @font-size(16);
  47. ========================================================================== */
  48. @mixin font-size($size) {
  49. font-size: 0px + $size;
  50. font-size: 0rem + $size / $doc-font-size;
  51. line-height: 0 + round($doc-line-height / $size*10000) / 10000;
  52. margin-bottom: 0px + $doc-line-height;
  53. margin-bottom: 0rem + ($doc-line-height / $doc-font-size);
  54. }
  55. /*
  56. Just font-size (REMs + pixel fallback)
  57. example: @include font-rem(16);
  58. ========================================================================== */
  59. @mixin font-rem($size) {
  60. font-size: 0px + $size;
  61. font-size: 0rem + $size / $doc-font-size;
  62. }
  63. /*
  64. Just font-size (REMs + pixel fallback) and line-height
  65. @include font(16);
  66. ========================================================================== */
  67. @mixin font($size) {
  68. font-size: 0px + $size;
  69. font-size: 0rem + $size / $doc-font-size;
  70. line-height: 0 + round($doc-line-height / $size*10000) / 10000;
  71. }
  72. /*
  73. Hide text overflow and end with ...
  74. ========================================================================== */
  75. @mixin text-overflow() {
  76. overflow: hidden;
  77. text-overflow: ellipsis;
  78. white-space: nowrap;
  79. }
  80. /* Indentation variable */
  81. $indent-var: 0rem + ($doc-line-height / $doc-font-size);
  82. /* ==========================================================================
  83. Gradient mixins
  84. ========================================================================== */
  85. @mixin horizontal($startColor : $white, $endColor : $lightergrey) {
  86. background-color: $endColor;
  87. background-image : -webkit-gradient(linear, 0 0, 100% 0, from($startColor), to($endColor)); // Safari 4+, Chrome 2+
  88. background-image : -webkit-linear-gradient(left, $startColor, $endColor); // Safari 5.1+, Chrome 10+
  89. background-image : -moz-linear-gradient(left, $startColor, $endColor); // FF 3.6+
  90. background-image : -ms-linear-gradient(left, $startColor, $endColor); // IE10
  91. background-image : -o-linear-gradient(left, $startColor, $endColor); // Opera 11.10
  92. background-image : linear-gradient(left, $startColor, $endColor); // W3C
  93. background-repeat : repeat-x;
  94. }
  95. @mixin vertical($startColor : $white, $endColor: $lightergrey) {
  96. background-image : -webkit-gradient(linear, 0 0, 0 100%, from($startColor), to($endColor)); // Safari 4+, Chrome 2+
  97. background-image : -webkit-linear-gradient(top, $startColor, $endColor); // Safari 5.1+, Chrome 10+
  98. background-color : $endColor;
  99. background-image : -moz-linear-gradient(top, $startColor, $endColor); // FF 3.6+
  100. background-image : -ms-linear-gradient(top, $startColor, $endColor); // IE10
  101. background-image : -o-linear-gradient(top, $startColor, $endColor); // Opera 11.10
  102. background-image : linear-gradient(top, $startColor, $endColor); // W3C
  103. background-repeat : repeat-x;
  104. }
  105. @mixin directional($startColor : $white, $endColor : $lightergrey, $deg : 45deg) {
  106. background-color : $endColor;
  107. background-image : -moz-linear-gradient($deg, $startColor, $endColor); // FF 3.6+
  108. background-image : -ms-linear-gradient($deg, $startColor, $endColor); // IE10
  109. background-image : -webkit-linear-gradient($deg, $startColor, $endColor); // Safari 5.1+, Chrome 10+
  110. background-image : -o-linear-gradient($deg, $startColor, $endColor); // Opera 11.10
  111. background-image : linear-gradient($deg, $startColor, $endColor); // W3C
  112. background-repeat : repeat-x;
  113. }
  114. // .bordered(COLOR, COLOR, COLOR, COLOR);
  115. @mixin bordered($top-color: #eee, $right-color: #eee, $bottom-color: #eee, $left-color: #eee) {
  116. border-top : solid 1px $top-color;
  117. border-left : solid 1px $left-color;
  118. border-right : solid 1px $right-color;
  119. border-bottom : solid 1px $bottom-color;
  120. }
  121. /* ==========================================================================
  122. Rounded corners
  123. ========================================================================== */
  124. /*
  125. Round all corners
  126. example: @include rounded(4px);
  127. ========================================================================== */
  128. @mixin rounded($radius:4px) {
  129. border-radius : $radius;
  130. }
  131. /*
  132. Round individual corners (top right, bottom right, bottom left, top left)
  133. example: @include border-radius(4px, 0, 0, 4px);
  134. ========================================================================== */
  135. @mixin border-radius($topright: 0, $bottomright: 0, $bottomleft: 0, $topleft: 0) {
  136. border-top-right-radius: $topright;
  137. border-bottom-right-radius: $bottomright;
  138. border-bottom-left-radius: $bottomleft;
  139. border-top-left-radius: $topleft;
  140. -webkit-background-clip: padding-box;
  141. -moz-background-clip: padding;
  142. background-clip: padding-box;
  143. }
  144. /*
  145. Box shadow
  146. example: @include box-shadow(HORIZONTAL VERTICAL BLUR COLOR));
  147. ========================================================================== */
  148. @mixin box-shadow($shadow: 0 1px 3px rgba(0,0,0,.25)) {
  149. -webkit-box-shadow: $shadow;
  150. -moz-box-shadow: $shadow;
  151. box-shadow: $shadow;
  152. }
  153. /*
  154. Drop shadow
  155. example: @include drop-shadow(HORIZONTAL, VERTICAL, BLUR, ALPHA);
  156. ========================================================================== */
  157. @mixin drop-shadow($x-axis: 0, $y-axis: 1px, $blur: 2px, $alpha: 0.1) {
  158. -webkit-box-shadow: $x-axis $y-axis $blur rgba(0, 0, 0, $alpha);
  159. -moz-box-shadow: $x-axis $y-axis $blur rgba(0, 0, 0, $alpha);
  160. box-shadow: $x-axis $y-axis $blur rgba(0, 0, 0, $alpha);
  161. }
  162. /*
  163. Text shadow
  164. example: @include text-shadow(0 2px 3px rgba(0,0,0,.25));
  165. ========================================================================== */
  166. @mixin text-shadow($shadow: 0 2px 3px rgba(0,0,0,.25)) {
  167. text-shadow: $shadow; }
  168. /*
  169. Opacity
  170. example: @include opacity(0.5); // 50% opacity
  171. ========================================================================== */
  172. @mixin opacity($opacity: 0.5) {
  173. opacity: $opacity;
  174. }
  175. /* ==========================================================================
  176. Transformations
  177. ========================================================================== */
  178. /*
  179. @include rotate(VALUEdeg);
  180. ========================================================================== */
  181. @mixin rotate($deg) {
  182. -webkit-transform: rotate($deg);
  183. -moz-transform: rotate($deg);
  184. -ms-transform: rotate($deg);
  185. -o-transform: rotate($deg);
  186. transform: rotate($deg);
  187. }
  188. /*
  189. @include scale(VALUE);
  190. ========================================================================== */
  191. @mixin scale($ratio) {
  192. -webkit-transform: scale($ratio);
  193. -moz-transform: scale($ratio);
  194. -ms-transform: scale($ratio);
  195. -o-transform: scale($ratio);
  196. transform: scale($ratio);
  197. }
  198. /*
  199. @include skew(VALUE, VALUE);
  200. ========================================================================== */
  201. @mixin skew($x: 0, $y: 0) {
  202. -webkit-transform: skew($x, $y);
  203. -moz-transform: skew($x, $y);
  204. -ms-transform: skew($x, $y);
  205. -o-transform: skew($x, $y);
  206. transform: skew($x, $y);
  207. }
  208. /*
  209. @include transition(PROPERTY DURATION DELAY(OPTIONAL) TIMING-FINCTION);
  210. ========================================================================== */
  211. @mixin transition($transition) {
  212. -webkit-transition: $transition;
  213. -moz-transition: $transition;
  214. -ms-transition: $transition;
  215. -o-transition: $transition;
  216. transition: $transition;
  217. }
  218. /*
  219. @include translate(VALUE, VALUE);
  220. ========================================================================== */
  221. @mixin translate($x: 0, $y: 0) {
  222. -webkit-transform: translate($x, $y);
  223. -moz-transform: translate($x, $y);
  224. -ms-transform: translate($x, $y);
  225. -o-transform: translate($x, $y);
  226. transform: translate($x, $y);
  227. }
  228. @mixin translate3d($x: 0, $y: 0, $z: 0) {
  229. -webkit-transform: translate($x, $y, $z);
  230. -moz-transform: translate($x, $y, $z);
  231. -ms-transform: translate($x, $y, $z);
  232. -o-transform: translate($x, $y, $z);
  233. transform: translate($x, $y, $z);
  234. }
  235. @mixin animation($name, $duration: 300ms, $delay: 0, $ease: ease) {
  236. -webkit-animation: $name $duration $delay $ease;
  237. -moz-animation: $name $duration $delay $ease;
  238. -ms-animation: $name $duration $delay $ease;
  239. }
  240. /* ==========================================================================
  241. Background
  242. ========================================================================== */
  243. /*
  244. @include background-alpha(VALUE VALUE);
  245. ========================================================================== */
  246. @mixin background-alpha($color: $white, $alpha: 1) {
  247. background-color: hsla(hue($color), saturation($color), lightness($color), $alpha);
  248. }
  249. /*
  250. @include background-size(VALUE VALUE);
  251. ========================================================================== */
  252. @mixin background-size($size){
  253. -webkit-background-size: $size;
  254. -moz-background-size: $size;
  255. -o-background-size: $size;
  256. background-size: $size;
  257. }
  258. /*
  259. Box-sizing
  260. example: @include box-sizing(VALUE); //(border-box, padding-box, content-box)
  261. ========================================================================== */
  262. @mixin box-sizing($boxsize: border-box) {
  263. -webkit-box-sizing: $boxsize;
  264. -moz-box-sizing: $boxsize;
  265. -ms-box-sizing: $boxsize;
  266. box-sizing: $boxsize;
  267. }
  268. /* ==========================================================================
  269. Image replacement
  270. ========================================================================== */
  271. @mixin hide-text() {
  272. text-indent: 100%;
  273. white-space: nowrap;
  274. overflow: hidden;
  275. }
  276. /*
  277. Hide from visual and speaking browsers
  278. ========================================================================== */
  279. @mixin hidden {
  280. display: none;
  281. visibility: hidden;
  282. }
  283. /*
  284. Hide but maintain layout
  285. ========================================================================== */
  286. @mixin invisible() {
  287. visibility: hidden;
  288. }
  289. /*
  290. Resize
  291. example: @include resize(VALUE); //(none, both, horizontal, vertical, inherit)
  292. ========================================================================== */
  293. @mixin resize($direction: both) {
  294. resize: $direction;
  295. overflow: auto;
  296. }
  297. /*
  298. Hidden but available to speaking browsers
  299. ========================================================================== */
  300. @mixin visuallyhidden() {
  301. overflow: hidden;
  302. position: absolute;
  303. clip: rect(0 0 0 0);
  304. height: 1px;
  305. width: 1px;
  306. margin: -1px;
  307. padding: 0;
  308. border: 0; }