我找到了一個flexbox/grid layout的SCSS mixin HERE。這種混合Flexbox /網格佈局SCSS mixin如何工作?
以下是完整的混入:
@mixin grid-col(
$col: null,
$grid-columns: 12,
$col-offset: null,
$gutter: null,
$condensed: false,
$align-self: null,
$flex-grow: 0,
$flex-shrink:1,
$flex-basis: auto,
$order: null,
$grid-type: skeleton,
$last-child: false
){
@if type-of($col) == number and unitless($col) == true {
$flex-grow: 0;
$flex-shrink: 0;
$flex-basis: percentage($col/$grid-columns);
@if $grid-type == skeleton {
@if $gutter and unit($gutter) == '%' {
$flex-basis: $flex-basis - $gutter;
} @else if $gutter and unitless($gutter) == false {
$flex-basis: calc(#{$flex-basis} - #{$gutter});
}
} @else if $grid-type == margin-offset {
@if $gutter and unit($gutter) == '%' {
$flex-basis: (100% - ($gutter * ($grid-columns/$col - 1)))/($grid-columns/$col);
} @else if $gutter and unitless($gutter) == false {
$flex-basis: calc(#{$flex-basis} - #{$gutter * ($grid-columns/$col - 1)/($grid-columns/$col)});
}
}
@if $col-offset and unit($col-offset) == '%' {
$flex-basis: $flex-basis + $col-offset;
} @else if $col-offset and unitless($col-offset) == false {
$flex-basis: calc(#{$flex-basis} + #{$col-offset});
}
} @else if type-of($col) == number and unitless($col) == false {
$flex-grow: 0;
$flex-shrink: 0;
$flex-basis: $col;
} @else if type-of($col) == string and $col == 'auto' {
$flex-grow: 1;
$flex-shrink: 1;
$flex-basis: auto;
max-width: 100%;
width: auto;
} @else if type-of($col) == string and $col == 'equal' {
// flex: 1
$flex-grow: 1;
$flex-shrink: 1;
$flex-basis: 0;
} @else if type-of($col) == string and $col == 'none' {
// flex: none
$flex-grow: 0;
$flex-shrink: 0;
$flex-basis: auto;
} @else if type-of($col) == string and $col == 'initial' {
// flex: initial
$flex-grow: 0;
$flex-shrink: 1;
$flex-basis: auto;
} @else if type-of($col) == string and $col == 'breakpoint' {
$flex-grow: 0;
$flex-shrink: 1;
$flex-basis: auto;
width: 100%;
}
flex: $flex-grow $flex-shrink $flex-basis;
@if $align-self {
align-self: $align-self;
}
@if type-of($order) == number {
order: $order;
}
@if $gutter and unitless($gutter) == false {
@if $grid-type == skeleton {
@if $condensed == true {
@include grid-gutter($margin: 0 $gutter/2);
} @else {
@include grid-gutter($margin: 0 $gutter/2 $gutter);
}
} @else if $grid-type == margin-offset {
@if type-of($col) == string and $col == 'breakpoint' {
@include grid-gutter($margin-right: 0);
} @else if $last-child {
@include grid-gutter($margin-right: 0);
} @else {
@include grid-gutter($margin-right: $gutter);
}
@if $condensed == false {
@include grid-gutter($margin-bottom: $gutter);
}
}
}
@content;
}
我不明白這個混入所有參數的意思做,例如$condensed: false,
。我曾與flexbox和Scss合作過很多次,但我只是覺得這個mixin稍微超出了我的視野。
具體來說,我掙扎理解混入的這一部分:
@else if $grid-type == margin-offset {
@if $gutter and unit($gutter) == '%' {
$flex-basis: (100% - ($gutter * ($grid-columns/$col - 1)))/($grid-columns/$col);
} @else if $gutter and unitless($gutter) == false {
$flex-basis: calc(#{$flex-basis} - #{$gutter * ($grid-columns/$col - 1)/($grid-columns/$col)});
}
}
有人能解釋一下這部分給我嗎?
@LGSon這個問題的原因在那裏很差 - 它會很快被拒絕並關閉,請參閱[爲什麼實施和調試問題與軟件工程的主題無關?](https://softwareengineering.meta.stackexchange.com/q/7864/ 31260)推薦閱讀:** [軟件工程(以前稱爲程序員)是怎麼回事?堆棧溢出指南](https://softwareengineering.meta.stackexchange。com/q/7182/31260)** – gnat
@gnat好的,但我已經從_Software Engineering_改爲_Code Review _....? IYO,那是個好地方嗎?或者你會有什麼建議? – LGSon
幾乎沒有@LGSon - 請參閱[他們的幫助中心](https://codereview.stackexchange.com/help/on-topic)中的「六是」要求,它看起來並不符合以下要求:「To據我所知,代碼是否按預期工作?「 – gnat