_mixins.scss 9.3 KB

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