🍓classes of flex-stylus
使用stylus预处理器封装的flex布局类~ 只提供源码 业务项目自行构建
- 简化常用布局✂️
- 解决一次又一次的布局兼容性问题😤ios >= 8 android >= 4.3
npm i flex-stylus-class --save-dev
or
yarn add flex-stylus-class
// @file index.styl
@import '~flex-stylus-class'
or
// @file index.js
import 'flex-stylus-class'
- 建议使用webpack4构建工具
- 建议使用
postcss-loader + autoprefixer + cssnano
进行样式的兼容性、代码压缩处理
// install
yarn add postcss-loader autoprefixer cssnano
// @file postcss.config.js
module.exports = {
plugins: [
require('autoprefixer'),
require('cssnano')({
preset: 'default'
}),
]
};
// @file package.json browserslist
...,
"browserslist": [
"iOS >= 8",
"Android >= 4.3"
]
特别注意:browserslist
中一定要写ios >= 8
, 否则iphone5s (ios8.3)会出现布局错乱的兼容性问题。
body *
box-sizing border-box
.item
height 50px
width 50px
background-color #E0E0E0
margin 10px
section
border 1px solid #424242
.section-200
height 200px
width 200px
<section class=" c__flex">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</section>
<section class=" c__flex c__flex-auto">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</section>
<section class=" c__flex c__wrap">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</section>
<section class=" c__flex c__center">
<div class="item"></div>
<div class="item"></div>
</section>
// space-between 写法
<section class=" c__flex c__wrap c__between">
// space-around 写法
// <section class=" c__flex c__wrap c__around">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</section>
<section class="section-200 c__flex c__around">
<div class="item"></div>
<div class="item i__middle"></div>
<div class="item i__bottom"></div>
</section>
<section class="c__vertical c__flex c__middle">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</section>
<section class="section-200 c__flex c__center c__middle">
<div class="item"></div>
</section>
<section class="c__flex c__flex-equal">
<section class="c__flex c__vertical c__middle">
<div class="item"></div>
<div class="item"></div>
</section>
<div class="item"></div>
<div class="item"></div>
</section>
特别注意:ios10-
已知的flex-direction:column
bug, 父元素为垂直flex布局时,子元素必须为display:block
元素,所以要像下面这样,在水平flex元素外套一层block
元素。
<section class="c__flex c__vertical c__middle">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<section>
<div class="c__flex">
<div class="item"></div>
<div class="item"></div>
</div>
</section>
</section>
MIT