_mixins.scss 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. @mixin clearfix() {
  2. &::after {
  3. content: "";
  4. display: table;
  5. clear: both;
  6. }
  7. }
  8. // Box sizing
  9. @mixin box-sizing($boxmodel) {
  10. box-sizing: $boxmodel;
  11. }
  12. @mixin tab-focus() {
  13. // Default
  14. outline: thin dotted;
  15. // WebKit
  16. outline: 5px auto -webkit-focus-ring-color;
  17. outline-offset: -2px;
  18. }
  19. // Center-align a block level element
  20. // ----------------------------------
  21. @mixin center-block() {
  22. display: block;
  23. margin-left: auto;
  24. margin-right: auto;
  25. }
  26. // Sizing shortcuts
  27. // -------------------------
  28. @mixin size($height, $width) {
  29. width: $width;
  30. height: $height;
  31. }
  32. @mixin square($size) {
  33. @include size($size, $size);
  34. }
  35. // Placeholder text
  36. // -------------------------
  37. @mixin placeholder($color: $placeholderText) {
  38. &:-moz-placeholder {
  39. color: $color;
  40. }
  41. &:-ms-input-placeholder {
  42. color: $color;
  43. }
  44. &::-webkit-input-placeholder {
  45. color: $color;
  46. }
  47. }
  48. // Text overflow
  49. // -------------------------
  50. // Requires inline-block or block for proper styling
  51. @mixin text-overflow() {
  52. overflow: hidden;
  53. text-overflow: ellipsis;
  54. white-space: nowrap;
  55. }
  56. // CSS image replacement
  57. // -------------------------
  58. // Source: https://github.com/h5bp/html5-boilerplate/commit/aa0396eae757
  59. .hide-text {
  60. font: 0/0 a;
  61. color: transparent;
  62. text-shadow: none;
  63. background-color: transparent;
  64. border: 0;
  65. }
  66. // FONTS
  67. // --------------------------------------------------
  68. @mixin font-family-serif() {
  69. font-family: $font-family-serif;
  70. }
  71. @mixin font-family-sans-serif() {
  72. font-family: $font-family-sans-serif;
  73. }
  74. @mixin font-family-monospace() {
  75. font-family: $font-family-monospace;
  76. }
  77. @mixin font-shorthand($size: $font-size-base, $weight: normal, $lineHeight: $line-height-base) {
  78. font-size: $size;
  79. font-weight: $weight;
  80. line-height: $lineHeight;
  81. }
  82. @mixin font-serif($size: $font-size-base, $weight: normal, $lineHeight: $line-height-base) {
  83. @include font-family-serif();
  84. @include font-shorthand($size, $weight, $lineHeight);
  85. }
  86. @mixin font-sans-serif($size: $font-size-base, $weight: normal, $lineHeight: $line-height-base) {
  87. @include font-family-sans-serif();
  88. @include font-shorthand($size, $weight, $lineHeight);
  89. }
  90. @mixin monospace($size: $font-size-base, $weight: normal, $lineHeight: $line-height-base) {
  91. @include font-family-monospace;
  92. @include font-shorthand($size, $weight, $lineHeight);
  93. }
  94. // FORMS
  95. // --------------------------------------------------
  96. // Block level inputs
  97. .input-block-level {
  98. display: block;
  99. width: 100%;
  100. min-height: $input-line-height; // Make inputs at least the height of their button counterpart (base line-height + padding + border)
  101. @include box-sizing(border-box); // Makes inputs behave like true block-level elements
  102. }
  103. // CSS3 PROPERTIES
  104. // --------------------------------------------------
  105. // Border Radius
  106. @mixin border-radius($radius) {
  107. -webkit-border-radius: $radius;
  108. -moz-border-radius: $radius;
  109. border-radius: $radius;
  110. }
  111. // Single Corner Border Radius
  112. @mixin border-top-left-radius($radius) {
  113. -webkit-border-top-left-radius: $radius;
  114. -moz-border-radius-topleft: $radius;
  115. border-top-left-radius: $radius;
  116. }
  117. @mixin border-top-right-radius($radius) {
  118. -webkit-border-top-right-radius: $radius;
  119. -moz-border-radius-topright: $radius;
  120. border-top-right-radius: $radius;
  121. }
  122. @mixin border-bottom-right-radius($radius) {
  123. -webkit-border-bottom-right-radius: $radius;
  124. -moz-border-radius-bottomright: $radius;
  125. border-bottom-right-radius: $radius;
  126. }
  127. @mixin border-bottom-left-radius($radius) {
  128. -webkit-border-bottom-left-radius: $radius;
  129. -moz-border-radius-bottomleft: $radius;
  130. border-bottom-left-radius: $radius;
  131. }
  132. // Single Side Border Radius
  133. @mixin border-top-radius($radius) {
  134. @include border-top-right-radius($radius);
  135. @include border-top-left-radius($radius);
  136. }
  137. @mixin border-right-radius($radius) {
  138. @include border-top-right-radius($radius);
  139. @include border-bottom-right-radius($radius);
  140. }
  141. @mixin border-bottom-radius($radius) {
  142. @include border-bottom-right-radius($radius);
  143. @include border-bottom-left-radius($radius);
  144. }
  145. @mixin border-left-radius($radius) {
  146. @include border-top-left-radius($radius);
  147. @include border-bottom-left-radius($radius);
  148. }
  149. // Drop shadows
  150. @mixin box-shadow($shadow) {
  151. box-shadow: $shadow;
  152. }
  153. // Transitions
  154. @mixin transition($transition) {
  155. transition: $transition;
  156. }
  157. @mixin transition-delay($transition-delay) {
  158. transition-delay: $transition-delay;
  159. }
  160. @mixin transition-duration($transition-duration) {
  161. transition-duration: $transition-duration;
  162. }
  163. // Transformations
  164. @mixin rotate($degrees) {
  165. transform: rotate($degrees);
  166. }
  167. @mixin scale($ratio) {
  168. transform: scale($ratio);
  169. }
  170. @mixin translate($x, $y) {
  171. transform: translate($x, $y);
  172. }
  173. @mixin skew($x, $y) {
  174. transform: skew($x, $y);
  175. -webkit-backface-visibility: hidden; // See https://github.com/twbs/bootstrap/issues/5319
  176. }
  177. @mixin translate3d($x, $y, $z) {
  178. transform: translate3d($x, $y, $z);
  179. }
  180. @mixin backface-visibility($visibility) {
  181. backface-visibility: $visibility;
  182. }
  183. // Heads up: FF 3.6 and under need "padding" instead of "padding-box"
  184. @mixin background-clip($clip) {
  185. background-clip: $clip;
  186. }
  187. // Background sizing
  188. @mixin background-size($size) {
  189. background-size: $size;
  190. }
  191. // User select
  192. // For selecting text on the page
  193. @mixin user-select($select) {
  194. user-select: $select;
  195. }
  196. // Resize anything
  197. @mixin resizable($direction) {
  198. resize: $direction; // Options: horizontal, vertical, both
  199. overflow: auto; // Safari fix
  200. }
  201. // CSS3 Content Columns
  202. @mixin content-columns($columnCount, $columnGap: $gridGutterWidth) {
  203. -webkit-column-count: $columnCount;
  204. -moz-column-count: $columnCount;
  205. column-count: $columnCount;
  206. -webkit-column-gap: $columnGap;
  207. -moz-column-gap: $columnGap;
  208. column-gap: $columnGap;
  209. }
  210. // Optional hyphenation
  211. @mixin hyphens($mode: auto) {
  212. word-wrap: break-word;
  213. -webkit-hyphens: $mode;
  214. -moz-hyphens: $mode;
  215. -ms-hyphens: $mode;
  216. -o-hyphens: $mode;
  217. hyphens: $mode;
  218. }
  219. // Opacity
  220. @mixin opacity($opacity) {
  221. opacity: $opacity / 100;
  222. }
  223. // BACKGROUNDS
  224. // --------------------------------------------------
  225. // Add an alphatransparency value to any background or border color (via Elyse Holladay)
  226. #translucent {
  227. @mixin background($color: $white, $alpha: 1) {
  228. background-color: hsla(hue($color), saturation($color), lightness($color), $alpha);
  229. }
  230. @mixin border($color: $white, $alpha: 1) {
  231. border-color: hsla(hue($color), saturation($color), lightness($color), $alpha);
  232. @include background-clip(padding-box);
  233. }
  234. }
  235. // Gradient Bar Colors for buttons and alerts
  236. @mixin gradientBar($primaryColor, $secondaryColor, $text-color: #fff, $textShadow: 0 -1px 0 rgba(0,0,0,.25)) {
  237. color: $text-color;
  238. text-shadow: $textShadow;
  239. @include gradient-vertical($primaryColor, $secondaryColor);
  240. border-color: $primaryColor;
  241. }
  242. // Gradients
  243. @mixin gradient-horizontal($startColor: #555, $endColor: #333) {
  244. background-color: $endColor;
  245. background-image: linear-gradient(to right, $startColor, $endColor); // Standard, IE10
  246. background-repeat: repeat-x;
  247. }
  248. @mixin gradient-vertical($startColor: #555, $endColor: #333) {
  249. background-color: mix($startColor, $endColor, 60%);
  250. background-image: linear-gradient(to bottom, $startColor, $endColor); // Standard, IE10
  251. background-repeat: repeat-x;
  252. }
  253. @mixin gradient-directional($startColor: #555, $endColor: #333, $deg: 45deg) {
  254. background-color: $endColor;
  255. background-repeat: repeat-x;
  256. background-image: linear-gradient($deg, $startColor, $endColor); // Standard, IE10
  257. }
  258. @mixin gradient-horizontal-three-colors($startColor: #00b3ee, $midColor: #7a43b6, $colorStop: 50%, $endColor: #c3325f) {
  259. background-color: mix($midColor, $endColor, 80%);
  260. background-image: linear-gradient(to right, $startColor, $midColor $colorStop, $endColor);
  261. background-repeat: no-repeat;
  262. }
  263. @mixin gradient-vertical-three-colors($startColor: #00b3ee, $midColor: #7a43b6, $colorStop: 50%, $endColor: #c3325f) {
  264. background-color: mix($midColor, $endColor, 80%);
  265. background-image: linear-gradient($startColor, $midColor $colorStop, $endColor);
  266. background-repeat: no-repeat;
  267. }
  268. @mixin gradient-radial($innerColor: #555, $outerColor: #333) {
  269. background-color: $outerColor;
  270. background-image: -webkit-gradient(radial, center center, 0, center center, 460, from($innerColor), to($outerColor));
  271. background-image: -webkit-radial-gradient(circle, $innerColor, $outerColor);
  272. background-image: -moz-radial-gradient(circle, $innerColor, $outerColor);
  273. background-image: -o-radial-gradient(circle, $innerColor, $outerColor);
  274. background-repeat: no-repeat;
  275. }
  276. @mixin striped($color: #555, $angle: 45deg) {
  277. background-color: $color;
  278. background-image: linear-gradient($angle, rgba(255,255,255,.15) 25%, transparent 25%, transparent 50%, rgba(255,255,255,.15) 50%, rgba(255,255,255,.15) 75%, transparent 75%, transparent);
  279. }
  280. @mixin left-brand-border() {
  281. border-left: 2px solid transparent;
  282. }
  283. @mixin left-brand-border-gradient() {
  284. border-image: linear-gradient(rgba(255,213,0,1) 0%, rgba(255,68,0,1) 99%, rgba(255,68,0,1) 100%);
  285. border-image-slice: 1;
  286. border-top: 0;
  287. border-right: 0;
  288. border-bottom: 0;
  289. border-left: 2px solid transparent;
  290. }
  291. @mixin brand-bottom-border() {
  292. border-image: $brand-gradient;
  293. border-image-slice: 1;
  294. border-top: 0;
  295. border-right: 0;
  296. border-left: 0;
  297. border-bottom: 1px solid transparent;
  298. }