_flex-box.scss 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. // CSS3 Flexible Box Model and property defaults
  2. // Custom shorthand notation for flexbox
  3. @mixin box($orient: inline-axis, $pack: start, $align: stretch) {
  4. @include display-box;
  5. @include box-orient($orient);
  6. @include box-pack($pack);
  7. @include box-align($align);
  8. }
  9. @mixin display-box {
  10. display: -webkit-box;
  11. display: -moz-box;
  12. display: -ms-flexbox; // IE 10
  13. display: box;
  14. }
  15. @mixin box-orient($orient: inline-axis) {
  16. // horizontal|vertical|inline-axis|block-axis|inherit
  17. @include prefixer(box-orient, $orient, webkit moz spec);
  18. }
  19. @mixin box-pack($pack: start) {
  20. // start|end|center|justify
  21. @include prefixer(box-pack, $pack, webkit moz spec);
  22. -ms-flex-pack: $pack; // IE 10
  23. }
  24. @mixin box-align($align: stretch) {
  25. // start|end|center|baseline|stretch
  26. @include prefixer(box-align, $align, webkit moz spec);
  27. -ms-flex-align: $align; // IE 10
  28. }
  29. @mixin box-direction($direction: normal) {
  30. // normal|reverse|inherit
  31. @include prefixer(box-direction, $direction, webkit moz spec);
  32. -ms-flex-direction: $direction; // IE 10
  33. }
  34. @mixin box-lines($lines: single) {
  35. // single|multiple
  36. @include prefixer(box-lines, $lines, webkit moz spec);
  37. }
  38. @mixin box-ordinal-group($int: 1) {
  39. @include prefixer(box-ordinal-group, $int, webkit moz spec);
  40. -ms-flex-order: $int; // IE 10
  41. }
  42. @mixin box-flex($value: 0.0) {
  43. @include prefixer(box-flex, $value, webkit moz spec);
  44. -ms-flex: $value; // IE 10
  45. }
  46. @mixin box-flex-group($int: 1) {
  47. @include prefixer(box-flex-group, $int, webkit moz spec);
  48. }
  49. // CSS3 Flexible Box Model and property defaults
  50. // Unified attributes for 2009, 2011, and 2012 flavours.
  51. // 2009 - display (box | inline-box)
  52. // 2011 - display (flexbox | inline-flexbox)
  53. // 2012 - display (flex | inline-flex)
  54. @mixin display($value) {
  55. // flex | inline-flex
  56. @if $value == "flex" {
  57. // 2009
  58. display: -webkit-box;
  59. display: -moz-box;
  60. display: box;
  61. // 2012
  62. display: -webkit-flex;
  63. display: -moz-flex;
  64. display: -ms-flexbox; // 2011 (IE 10)
  65. display: flex;
  66. }
  67. @elseif $value == "inline-flex" {
  68. display: -webkit-inline-box;
  69. display: -moz-inline-box;
  70. display: inline-box;
  71. display: -webkit-inline-flex;
  72. display: -moz-inline-flex;
  73. display: -ms-inline-flexbox;
  74. display: inline-flex;
  75. }
  76. @else {
  77. display: $value;
  78. }
  79. }
  80. // 2009 - box-flex (integer)
  81. // 2011 - flex (decimal | width decimal)
  82. // 2012 - flex (integer integer width)
  83. @mixin flex($value) {
  84. // Grab flex-grow for older browsers.
  85. $flex-grow: nth($value, 1);
  86. // 2009
  87. @include prefixer(box-flex, $flex-grow, webkit moz spec);
  88. // 2011 (IE 10), 2012
  89. @include prefixer(flex, $value, webkit moz ms spec);
  90. }
  91. // 2009 - box-orient ( horizontal | vertical | inline-axis | block-axis)
  92. // - box-direction (normal | reverse)
  93. // 2011 - flex-direction (row | row-reverse | column | column-reverse)
  94. // 2012 - flex-direction (row | row-reverse | column | column-reverse)
  95. @mixin flex-direction($value: row) {
  96. // Alt values.
  97. $value-2009: $value;
  98. $value-2011: $value;
  99. $direction: "normal";
  100. @if $value == row {
  101. $value-2009: horizontal;
  102. }
  103. @elseif $value == "row-reverse" {
  104. $value-2009: horizontal;
  105. $direction: reverse;
  106. }
  107. @elseif $value == column {
  108. $value-2009: vertical;
  109. }
  110. @elseif $value == "column-reverse" {
  111. $value-2009: vertical;
  112. $direction: reverse;
  113. }
  114. // 2009
  115. @include prefixer(box-orient, $value-2009, webkit moz spec);
  116. @if $direction == "reverse" {
  117. @include prefixer(box-direction, $direction, webkit moz spec);
  118. }
  119. // 2012
  120. @include prefixer(flex-direction, $value, webkit moz spec);
  121. // 2011 (IE 10)
  122. -ms-flex-direction: $value;
  123. }
  124. // 2009 - box-lines (single | multiple)
  125. // 2011 - flex-wrap (nowrap | wrap | wrap-reverse)
  126. // 2012 - flex-wrap (nowrap | wrap | wrap-reverse)
  127. @mixin flex-wrap($value: nowrap) {
  128. // Alt values.
  129. $alt-value: $value;
  130. @if $value == nowrap {
  131. $alt-value: single;
  132. }
  133. @elseif $value == wrap {
  134. $alt-value: multiple;
  135. }
  136. @elseif $value == "wrap-reverse" {
  137. $alt-value: multiple;
  138. }
  139. @include prefixer(box-lines, $alt-value, webkit moz spec);
  140. @include prefixer(flex-wrap, $value, webkit moz ms spec);
  141. }
  142. // 2009 - TODO: parse values into flex-direction/flex-wrap
  143. // 2011 - TODO: parse values into flex-direction/flex-wrap
  144. // 2012 - flex-flow (flex-direction || flex-wrap)
  145. @mixin flex-flow($value) {
  146. @include prefixer(flex-flow, $value, webkit moz spec);
  147. }
  148. // 2009 - box-ordinal-group (integer)
  149. // 2011 - flex-order (integer)
  150. // 2012 - order (integer)
  151. @mixin order($int: 0) {
  152. // 2009
  153. @include prefixer(box-ordinal-group, $int, webkit moz spec);
  154. // 2012
  155. @include prefixer(order, $int, webkit moz spec);
  156. // 2011 (IE 10)
  157. -ms-flex-order: $int;
  158. }
  159. // 2012 - flex-grow (number)
  160. @mixin flex-grow($number: 0) {
  161. @include prefixer(flex-grow, $number, webkit moz spec);
  162. -ms-flex-positive: $number;
  163. }
  164. // 2012 - flex-shrink (number)
  165. @mixin flex-shrink($number: 1) {
  166. @include prefixer(flex-shrink, $number, webkit moz spec);
  167. -ms-flex-negative: $number;
  168. }
  169. // 2012 - flex-basis (number)
  170. @mixin flex-basis($width: auto) {
  171. @include prefixer(flex-basis, $width, webkit moz spec);
  172. -ms-flex-preferred-size: $width;
  173. }
  174. // 2009 - box-pack (start | end | center | justify)
  175. // 2011 - flex-pack (start | end | center | justify)
  176. // 2012 - justify-content (flex-start | flex-end | center | space-between | space-around)
  177. @mixin justify-content ($value: flex-start) {
  178. // Alt values.
  179. $alt-value: $value;
  180. @if $value == "flex-start" {
  181. $alt-value: start;
  182. }
  183. @elseif $value == "flex-end" {
  184. $alt-value: end;
  185. }
  186. @elseif $value == "space-between" {
  187. $alt-value: justify;
  188. }
  189. @elseif $value == "space-around" {
  190. $alt-value: center;
  191. }
  192. // 2009
  193. @include prefixer(box-pack, $alt-value, webkit moz spec);
  194. // 2012
  195. @include prefixer(justify-content, $value, webkit moz ms o spec);
  196. // 2011 (IE 10)
  197. -ms-flex-pack: $alt-value;
  198. }
  199. // 2009 - box-align (start | end | center | baseline | stretch)
  200. // 2011 - flex-align (start | end | center | baseline | stretch)
  201. // 2012 - align-items (flex-start | flex-end | center | baseline | stretch)
  202. @mixin align-items($value: stretch) {
  203. $alt-value: $value;
  204. @if $value == "flex-start" {
  205. $alt-value: start;
  206. }
  207. @elseif $value == "flex-end" {
  208. $alt-value: end;
  209. }
  210. // 2009
  211. @include prefixer(box-align, $alt-value, webkit moz spec);
  212. // 2012
  213. @include prefixer(align-items, $value, webkit moz ms o spec);
  214. // 2011 (IE 10)
  215. -ms-flex-align: $alt-value;
  216. }
  217. // 2011 - flex-item-align (auto | start | end | center | baseline | stretch)
  218. // 2012 - align-self (auto | flex-start | flex-end | center | baseline | stretch)
  219. @mixin align-self($value: auto) {
  220. $value-2011: $value;
  221. @if $value == "flex-start" {
  222. $value-2011: start;
  223. }
  224. @elseif $value == "flex-end" {
  225. $value-2011: end;
  226. }
  227. // 2012
  228. @include prefixer(align-self, $value, webkit moz spec);
  229. // 2011 (IE 10)
  230. -ms-flex-item-align: $value-2011;
  231. }
  232. // 2011 - flex-line-pack (start | end | center | justify | distribute | stretch)
  233. // 2012 - align-content (flex-start | flex-end | center | space-between | space-around | stretch)
  234. @mixin align-content($value: stretch) {
  235. $value-2011: $value;
  236. @if $value == "flex-start" {
  237. $value-2011: start;
  238. }
  239. @elseif $value == "flex-end" {
  240. $value-2011: end;
  241. }
  242. @elseif $value == "space-between" {
  243. $value-2011: justify;
  244. }
  245. @elseif $value == "space-around" {
  246. $value-2011: distribute;
  247. }
  248. // 2012
  249. @include prefixer(align-content, $value, webkit moz spec);
  250. // 2011 (IE 10)
  251. -ms-flex-line-pack: $value-2011;
  252. }