1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- // 主轴方向 属性值
- $directionList: row , row-reverse , column , column-reverse;
- // 主轴对齐方式 属性值
- $justifyContentList: flex-start , flex-end , center , space-between , space-around;
- // 交叉轴对齐方式 属性值
- $alignItemsList: flex-start , flex-end , center , baseline , stretch;
- // 三层遍历,组合所有属性值
- @each $direction in $directionList {
-
- // 简化一些属性值
- $dir: $direction;
- @if $direction == 'row' {
- $dir: 'x';
- }
- @if $direction == 'column' {
- $dir: 'y';
- }
- @each $justifyContent in $justifyContentList {
- // 简化一些属性值
- $JC: $justifyContent;
- @if $justifyContent == 'flex-start' {
- $JC: 'start';
- }
- @if $justifyContent == 'flex-end' {
- $JC: 'end';
- }
- @if $justifyContent == 'space-between' {
- $JC: 'between';
- }
- @if $justifyContent == 'space-around' {
- $JC: 'around';
- }
- @each $alignItems in $alignItemsList {
- // 简化一些属性值
- $AI: $alignItems;
- @if $alignItems == 'flex-start' {
- $AI: 'start';
- }
- @if $alignItems == 'flex-end' {
- $AI: 'end';
- }
-
- // 根据变量,组合为css代码
- @if $AI == 'center' {
- .flex-#{$dir}-#{$JC} {
- display: flex;
- flex-direction: $direction;
- justify-content: $justifyContent;
- align-items: center;
- }
- }
- @else {
- .flex-#{$dir}-#{$JC}-#{$AI} {
- display: flex;
- flex-direction: $direction;
- justify-content: $justifyContent;
- align-items: $alignItems;
- }
- }
- }
- }
- }
|