flex.scss 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // 主轴方向 属性值
  2. $directionList: row , row-reverse , column , column-reverse;
  3. // 主轴对齐方式 属性值
  4. $justifyContentList: flex-start , flex-end , center , space-between , space-around;
  5. // 交叉轴对齐方式 属性值
  6. $alignItemsList: flex-start , flex-end , center , baseline , stretch;
  7. // 三层遍历,组合所有属性值
  8. @each $direction in $directionList {
  9. // 简化一些属性值
  10. $dir: $direction;
  11. @if $direction == 'row' {
  12. $dir: 'x';
  13. }
  14. @if $direction == 'column' {
  15. $dir: 'y';
  16. }
  17. @each $justifyContent in $justifyContentList {
  18. // 简化一些属性值
  19. $JC: $justifyContent;
  20. @if $justifyContent == 'flex-start' {
  21. $JC: 'start';
  22. }
  23. @if $justifyContent == 'flex-end' {
  24. $JC: 'end';
  25. }
  26. @if $justifyContent == 'space-between' {
  27. $JC: 'between';
  28. }
  29. @if $justifyContent == 'space-around' {
  30. $JC: 'around';
  31. }
  32. @each $alignItems in $alignItemsList {
  33. // 简化一些属性值
  34. $AI: $alignItems;
  35. @if $alignItems == 'flex-start' {
  36. $AI: 'start';
  37. }
  38. @if $alignItems == 'flex-end' {
  39. $AI: 'end';
  40. }
  41. // 根据变量,组合为css代码
  42. @if $AI == 'center' {
  43. .flex-#{$dir}-#{$JC} {
  44. display: flex;
  45. flex-direction: $direction;
  46. justify-content: $justifyContent;
  47. align-items: center;
  48. }
  49. }
  50. @else {
  51. .flex-#{$dir}-#{$JC}-#{$AI} {
  52. display: flex;
  53. flex-direction: $direction;
  54. justify-content: $justifyContent;
  55. align-items: $alignItems;
  56. }
  57. }
  58. }
  59. }
  60. }