Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
quick flex layout
@mixin flex {
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
}
/**
* 主轴对齐方向 box
* @params flex-start flex-end center space-between
*/
@mixin justify-content ($justify) {
@if $justify == flex-start {
-webkit-box-pack: start;
} @else if $justify == flex-end {
-webkit-box-pack: end;
} @else if $justify == space-between {
-webkit-box-pack: justify;
} @else {
-webkit-box-pack: $justify;
}
-moz-justify-content: $justify;
-webkit-justify-content: $justify;
justify-content: $justify;
}
/**
* 交叉轴对齐方向 box
* @params flex-start flex-end center baseline stretch
*/
@mixin align-items ($align) {
@if $align == flex-start {
-webkit-box-pack: start;
} @else if $align == flex-end {
-webkit-box-pack: end;
} @else {
-webkit-box-align: $align;
}
-moz-align-items: $align;
-webkit-align-items: $align;
align-items: $align;
}
/**
* 子元素的显示方向 box
* @params row row-reverse column column-reverse
*/
@mixin flex-direction ($direction) {
@if $direction == row {
-webkit-box-direction: normal;
-webkit-box-orient: horizontal;
} @else if $direction == row-reverse {
-webkit-box-pack: end;
-webkit-box-direction: reverse;
-webkit-box-orient: horizontal;
} @else if $direction == column {
-webkit-box-direction: normal;
-webkit-box-orient: vertical;
} @else if $direction == column-reverse {
-webkit-box-pack: end;
-webkit-box-direction: reverse;
-webkit-box-orient: vertical;
} @else {
-webkit-box-align: $align;
}
-moz-flex-direction: $direction;
-webkit-flex-direction: $direction;
flex-direction: $direction;
}
/**
* 是否允许子元素伸缩 item
* @params {integer}
*/
@mixin flex-grow ($grow) {
@if $grow == 0 {
-webkit-box-flex: 0.0;
} @else {
-webkit-box-flex: 1+$grow/10;
}
-moz-flex-grow: $grow;
-webkit-flex-grow: $grow;
flex-grow: $grow;
}
@mixin flex-shrink ($grow) {
@if $grow == 0 {
-webkit-box-flex: 0.0;
} @else {
-webkit-box-flex: 1+$grow/10;
}
-moz-flex-shrink: $grow;
-webkit-flex-shrink: $grow;
flex-shrink: $grow;
}
/**
* 子元素的显示次序 item
* @params {integer}
*/
@mixin flex-order ($order) {
-webkit-box-ordinal-group: $order;
-moz-order: $order;
-webkit-order: $order;
order: $order;
}
@lingziyu

This comment has been minimized.

Copy link

commented Aug 23, 2018

请问 -webkit-box-flex: 1+$grow/10; 这里计算的依据是什么呀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.