您可以使用简单的 SCSS 函数和变量创建自己有用的 CSS 类,如下所示:
// space generation variables
$spaceamounts: (0, 5, 10, 15, 20, 25, 30, 35, 40, 45,
50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100); // Adjust this to include the pixel amounts you need.
$sides: (top, bottom, left, right); // all positions
@each $space in $spaceamounts {
@each $side in $sides {
.m#{str-slice($side, 0, 1)}-#{$space} {
margin-#{$side}: #{$space}px !important;
}
.p#{str-slice($side, 0, 1)}-#{$space} {
padding-#{$side}: #{$space}px !important;
}
}
}
@each $space in $spaceamounts {
.m-#{$space} {
margin: #{$space}px !important;
}
.p-#{$space} {
padding: #{$space}px !important;
}
}
这是我们在 Angular 9 Flex 项目中用来获取边距和内边距类的方法。