_mixins.scss 9.3 KB

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