hailu
2023-05-25 3644568ac3b6db7e387d5ab72da717e51626f869
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// flex(主轴,交叉轴,方向,换行,多轴线对齐)
@mixin flex($justify: null, $align: null, $direction: null, $warp: null, $warpAlign: null) {
    display: flex;
 
    @if $direction != null {
        @include flex-direction($direction);
    }
    @if $justify != null {
        @include flex-justify($justify);
    }
    @if $align != null {
        @include flex-align($align);
    }
    @if $warp != null {
        @include flex-warp($warp);
    }
    @if $warpAlign != null {
        @include flex-warpAlign($warpAlign);
    }
}
 
// flex-self(对齐,(布满||固定),顺序)
@mixin flex-self($flex: null, $align: null, $order: null){
    @if $flex != null {
        @if $flex == full {
            flex: auto;
        } @else if $flex == keep {
            flex: none;
        } @else {
            @include flexError($flex, 'flex-self');
        }
    }
    
    @if $align != null {
        @include flex-selfAlign($align);
    }
    
    @if $order != null {
        @include flex-order($order);
    }
}
 
// flex错误提示
@mixin flexError($param, $type) {
    position: relative;
    background-color: #ff3c00 !important;
    overflow: hidden;
 
    &::after {
        position: absolute;
        bottom: 0;
        right: 0;
        padding: 0.5em;
        color: #ff3c00 !important;
        background-color: white !important;
        font-size: 12px;
        content: 'ErrorParam: #{$param} in #{$type}';
    }
}
 
// 项目的排列方向
@mixin flex-direction($direction: row) {
    @if $direction == column {
        flex-direction: column;
    } @else if $direction == row {
        flex-direction: row;
    } @else if $direction == row-reverse {
        flex-direction: row-reverse;
    } @else if $direction == column-reverse {
        flex-direction: column-reverse;
    } @else {
        @include flexError($direction, 'flex-direction');
    }
}
 
// 主轴上的对齐方式
@mixin flex-justify($justify: start) {
    @if $justify == start {
        justify-content: start;
    } @else if $justify == center {
        justify-content: center;
    } @else if $justify == end {
        justify-content: flex-end;
    } @else if $justify == between {
        justify-content: space-between;
    } @else if $justify == around {
        justify-content: space-around;
    } @else {
        @include flexError($justify, 'flex-justify');
    }
}
 
// 交叉轴上的对齐方式
@mixin flex-align($align: top) {
    @if $align == top {
        align-items: flex-start;
    } @else if $align == center {
        align-items: center;
    } @else if $align == bottom {
        align-items: flex-end;
    } @else {
        @include flexError($align, 'flex-align');
    }
}
 
// 换行
@mixin flex-warp($warp: wrap) {
    @if $warp == wrap {
        flex-wrap: wrap;
    } @else if $warp == nowrap {
        flex-wrap: nowrap;
    } @else if $warp == wrap-reverse {
        flex-wrap: wrap-reverse;
    } @else {
        @include flexError($warp, 'flex-wrap');
    }
}
 
// 换行多根轴线的对齐方式,如果项目只有一根轴线,该属性不起作用
@mixin flex-warpAlign($align: stretch) {
    @if $align == stretch {
        align-content: stretch;
    } @else if $align == top {
        align-content: flex-start;
    } @else if $align == center {
        align-content: center;
    } @else if $align == bottom {
        align-content: flex-end;
    } @else if $align == between {
        align-content: space-between;
    } @else if $align == around {
        align-content: space-around;
    } @else {
        @include flexError($align, 'flex-wrapAlign');
    }
}
 
// 单个项目有与其他项目不一样的对齐方式
@mixin flex-selfAlign($align: auto){
    @if $align == auto {
        align-self: auto;
    } @else if $align == top {
        align-self: flex-start;
    } @else if $align == center {
        align-self: center;
    } @else if $align == bottom {
        align-self: flex-end;
    } @else if $align == baseline {
        align-self: baseline ;
    } @else if $align == stretch {
        align-self: stretch;
    } @else {
        @include flexError($align, 'flex-self-align');
    }
}
 
// 项目的排列顺序,数值越小,排列越靠前,默认为0
@mixin flex-order($order: 0){
    @if $order == round($order) {
        order: $order; 
    } @else {
        @include flexError($order, 'flex-self-order');
    }
}