forked from ultimatedelman/sass-flexbox-mixin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flexbox.scss
96 lines (91 loc) · 3.81 KB
/
flexbox.scss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
@mixin flexcontainer($display: flex, $flexdirection: false, $flexwrap: false, $justifycontent: false, $alignitems: false, $aligncontent: false) {
/* values:
$display: flex | inline-flex
$flexdirection: row(default) | row-reverse | column | column-reverse
$flexwrap: nowrap(default) | wrap | wrap-reverse
$justifycontent: flex-start(default) | flex-end | center | space-between | space-around
$alignitems: flex-start | flex-end | center | baseline | stretch (default)
$aligncontent: flex-start | flex-end | center | space-between | space-around | stretch (default)
*/
.flexboxlegacy.no-flexbox & {
@include display-box;
@if $flexdirection { @include oldflexconvert(flex-direction, $flexdirection); }
@if $justifycontent { @include oldflexconvert(justifycontent, $justifycontent); }
@if $alignitems { @include oldflexconvert(align-items, $alignitems); }
}
.flexbox & {
@if $display == flex {
display: -ms-flexbox;
display: -moz-flex;
display: -webkit-flex;
display: flex;
}
@else {
display: -ms-inline-flexbox;
display: -moz-inline-flex;
display: -webkit-inline-flex;
display: inline-flex;
}
@if $flexdirection { @include flexprop(flex-direction, $flexdirection); }
@if $flexwrap { @include flexprop(flex-wrap, $flexwrap); }
@if $justifycontent { @include flexprop(justify-content, $justifycontent); }
@if $alignitems { @include flexprop(align-items, $alignitems); }
@if $aligncontent { @include flexprop(align-content, $aligncontent); }
}
}
@mixin flexchild($order: false, $flexgrow: 0, $flexshrink: 1, $flexbasis: auto, $alignself: false) {
.flexboxlegacy.no-flexbox & {
@include box-flex($flexgrow);
@if $order { @include box-ordinal-group($order + 1); } //legacy is 1-based
max-width: $flexbasis;
@include display-box;
}
.flexbox & {
@if $order { @include flexprop(order, $order); }
@include flexprop(flex, ($flexgrow $flexshrink $flexbasis));
@if $alignself { @include flexprop(align-self, $alignself); }
}
}
//translate for oldflex
@mixin oldflexconvert($prop, $value) {
@if $prop == flex-direction {
$dir: normal;
$orient: horizontal;
@if $value == row-reverse { $dir: reverse; }
@if $value == column { $orient: vertical; }
@if $value == column-reverse {
$orient: vertical;
$dir: reverse;
}
@include box-direction($dir);
@include box-orient($orient);
}
@if $prop == justify-content or $prop == align-items {
$newval: $value;
@if $value == flex-start { $newval: start; }
@if $value == flex-end { $newval: end; }
@if $value == space-between { $newval: justify; }
@if $value == space-around { $newval: justify; }
@if $prop == justify-content { @include box-pack($newval); }
@if $prop == align-items { @include box-align($newval); }
}
}
//translate for IE
@function ieflexvalue($value) {
@if $value == flex-start { @return start; }
@if $value == flex-end { @return end; }
@if $value == space-between { @return justify; }
@if $value == space-around { @return distribute; }
@if $value == justify-content { @return flex-pack; }
@if $value == align-items { @return flex-align; }
@if $value == align-content { @return flex-line-pack; }
@if $value == align-self { @return flex-item-align; }
@if $value == order { @return flex-order; }
@return $value;
}
@mixin flexprop($prop, $value) {
-webkit-#{$prop}: $value;
-moz-#{$prop}: $value;
-ms-#{ieflexvalue($prop)}: ieflexvalue($value);
#{$prop}: $value;
}