_mixins.scss 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. @charset "utf-8";
  2. /*
  3. * @file: SASS常用Function与Mixins
  4. * @update: 2015-06-03 17:17:50
  5. * @copyright: MIT License
  6. */
  7. /*
  8. * @name: inline-block
  9. * @param: $alignment {string} 对齐类型
  10. * @param: $support-for-ie {boolean} 是否支持IE6
  11. */
  12. @mixin inline-block($alignment: middle, $support-for-ie: true) {
  13. display: inline-block;
  14. @if $alignment and $alignment != none {
  15. vertical-align: $alignment;
  16. }
  17. @if $support-for-ie {
  18. *vertical-align: auto;
  19. *display: inline;
  20. zoom: 1;
  21. }
  22. }
  23. /* @name: 闭合浮动 */
  24. @mixin clearfix {
  25. *zoom: 1;
  26. &:before,
  27. &:after {
  28. content: "";
  29. display: table;
  30. line-height: 0;
  31. }
  32. &:after {
  33. clear: both;
  34. }
  35. }
  36. /*
  37. * @name: 浮动
  38. * @param: $side {string} 浮动方向
  39. * @param: $support-for-ie {boolean} 是否支持IE6
  40. */
  41. @mixin float($side: left, $support-for-ie: true) {
  42. float: unquote($side);
  43. @if $support-for-ie {
  44. _display: inline;
  45. }
  46. }
  47. /* @name: 文本隐藏 */
  48. @mixin hide-text {
  49. text-indent: 100%;
  50. white-space: nowrap;
  51. overflow: hidden;
  52. }
  53. /*
  54. * @name: 文字溢出显示省略号
  55. * @param: $width {dimension} 指定宽度 (需带单位)
  56. * 1. Opera 9-10.6
  57. * 2. Chrome 21+ bug https://bugs.webkit.org/show_bug.cgi?id=121902
  58. */
  59. @mixin ellipsis($width: auto) {
  60. @if($width) {
  61. width: $width;
  62. }
  63. white-space: nowrap;
  64. word-wrap: normal;
  65. overflow: hidden;
  66. -o-text-overflow: ellipsis; /* 1 */
  67. text-overflow: ellipsis;
  68. text-align: left; /* 2 */
  69. }
  70. /*
  71. * @name: 强制不换行
  72. * @link: http://www.hicss.net/solve-change-line-in-css
  73. */
  74. @mixin nowrap {
  75. white-space: nowrap;
  76. word-wrap: normal;
  77. word-break: keep-all;
  78. }
  79. /* @name: 连续字符换行 */
  80. @mixin break {
  81. -ms-word-break: break-all;
  82. word-break: break-all;
  83. word-break: break-word;
  84. }
  85. /* @name: 保留空白符序列,但是正常地进行换行 */
  86. @mixin pre {
  87. white-space: -moz-pre-wrap;
  88. white-space: -pre-wrap;
  89. white-space: -o-pre-wrap;
  90. white-space: pre-wrap;
  91. word-wrap: break-word;
  92. }
  93. /*
  94. * @name: resizable
  95. * @param: $direction {string} 缩放的方向 (horizontal || vertical || both)
  96. * @link: https://github.com/twbs/bootstrap-sass/blob/master/assets/stylesheets/bootstrap/mixins/_resize.scss
  97. * @1: Per CSS3 UI, `resize` only applies when `overflow` isn't `visible`
  98. */
  99. @mixin resizable($direction) {
  100. resize: $direction;
  101. overflow: auto; /* 1 */
  102. }
  103. /*
  104. * @name: 背景透明
  105. * @param: $color {color} 颜色
  106. * @param: $opacity {number} 透明度
  107. * @param: $support-for-ie {boolean} 是否支持IE6
  108. * @link: https://github.com/airen/Sass_mixins_function/tree/master/mixins
  109. */
  110. @mixin transparent($color, $opacity, $support-for-ie:true) {
  111. background-color: transparent;
  112. background-color: rgba($color, $opacity);
  113. @if $support-for-ie {
  114. filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#{ie-hex-str(rgba($color, $opacity))},endColorstr=#{ie-hex-str(rgba($color, $opacity))});
  115. zoom: 1;
  116. :root & {
  117. filter: none;
  118. }
  119. }
  120. }
  121. /*
  122. * @name: 透明度
  123. * @param: $opacity {number} 透明度
  124. * @param: $support-for-ie {boolean} 是否支持IE6
  125. */
  126. @mixin opacity($opacity:.65, $support-for-ie:true) {
  127. opacity: $opacity;
  128. @if $support-for-ie{
  129. $opacity-ie: $opacity * 100;
  130. filter: alpha(opacity=$opacity-ie); //IE8
  131. }
  132. }
  133. /* @name: 重置滤镜 */
  134. @mixin reset-filter {
  135. filter: progid:DXImageTransform.Microsoft.gradient(enabled = false);
  136. }
  137. /*
  138. * @name: border三角形
  139. * @param: $base {dimension} 底边尺寸
  140. * @param: $height {dimension} 高度
  141. * @param: $color {color} 颜色
  142. * @param: $direction {string} 方向 (top || bottom || left || right)
  143. * @link: http://codepen.io/zhouwenbin/pen/emZVZp
  144. */
  145. @mixin triangle($base, $height, $color, $direction) {
  146. font-size: 0;
  147. width: 0;
  148. height: 0;
  149. line-height: 0;
  150. overflow: hidden;
  151. display: inline-block;
  152. *display: inline;
  153. *zoom: 1;
  154. vertical-align: -2px;
  155. border-style: dashed;
  156. @if($direction == top) {
  157. border-width: $height $base / 2;
  158. border-color: transparent transparent $color;
  159. margin-top: -$height;
  160. }
  161. @if($direction == bottom) {
  162. border-width: $height $base / 2;
  163. border-color: $color transparent transparent;
  164. margin-bottom: -$height;
  165. }
  166. @if($direction == left) {
  167. border-width: $base / 2 $height;
  168. border-color: transparent transparent transparent $color;
  169. margin-right: -$height;
  170. }
  171. @if($direction == right) {
  172. border-width: $base / 2 $height;
  173. border-color: transparent $color transparent transparent;
  174. margin-left: -$height;
  175. }
  176. }
  177. /* @name: 按钮配色 */
  178. @mixin button-variant($color, $background, $border) {
  179. color: $color;
  180. background-color: $background;
  181. border-color: $border;
  182. &.is-hover,
  183. &:hover {
  184. color: $color;
  185. background-color: lighten($background, 8%);
  186. border-color: lighten($border, 10%);
  187. text-decoration: none; // 去掉a标签按钮的下划线
  188. }
  189. }
  190. /* @name: 按钮尺寸 */
  191. @mixin button-size($padding-vertical, $padding-horizontal, $font-size, $border-radius) {
  192. padding: $padding-vertical $padding-horizontal;
  193. font-size: $font-size;
  194. border-radius: $border-radius;
  195. }