_mixins.scss 9.6 KB

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