Flex Flex布局
Flex 是 CSS flex 布局的一个封装。
代码演示
基本示例
基础使用
import { Flex, WhiteSpace } from 'antd-mobile';
const PlaceHolder = ({ className = '', ...restProps }) => (
<div className={`${className} placeholder`} {...restProps}>Block</div>
);
const FlexExample = () => (
<div className="flex-container">
<div className="sub-title">Basic</div>
<Flex>
<Flex.Item><PlaceHolder /></Flex.Item>
<Flex.Item><PlaceHolder /></Flex.Item>
</Flex>
<WhiteSpace size="lg" />
<Flex>
<Flex.Item><PlaceHolder /></Flex.Item>
<Flex.Item><PlaceHolder /></Flex.Item>
<Flex.Item><PlaceHolder /></Flex.Item>
</Flex>
<WhiteSpace size="lg" />
<Flex>
<Flex.Item><PlaceHolder /></Flex.Item>
<Flex.Item><PlaceHolder /></Flex.Item>
<Flex.Item><PlaceHolder /></Flex.Item>
<Flex.Item><PlaceHolder /></Flex.Item>
</Flex>
<WhiteSpace size="lg" />
<div className="sub-title">Wrap</div>
<Flex wrap="wrap">
<PlaceHolder className="inline" />
<PlaceHolder className="inline" />
<PlaceHolder className="inline" />
<PlaceHolder className="inline" />
<PlaceHolder className="inline" />
<PlaceHolder className="inline" />
<PlaceHolder className="inline" />
</Flex>
<WhiteSpace size="lg" />
<div className="sub-title">Align</div>
<Flex justify="center">
<PlaceHolder className="inline" />
<PlaceHolder className="inline" />
<PlaceHolder className="inline" />
</Flex>
<WhiteSpace />
<Flex justify="end">
<PlaceHolder className="inline" />
<PlaceHolder className="inline" />
<PlaceHolder className="inline" />
</Flex>
<WhiteSpace />
<Flex justify="between">
<PlaceHolder className="inline" />
<PlaceHolder className="inline" />
<PlaceHolder className="inline" />
</Flex>
<WhiteSpace />
<Flex align="start">
<PlaceHolder className="inline" />
<PlaceHolder className="inline small" />
<PlaceHolder className="inline" />
</Flex>
<WhiteSpace />
<Flex align="end">
<PlaceHolder className="inline" />
<PlaceHolder className="inline small" />
<PlaceHolder className="inline" />
</Flex>
<WhiteSpace />
<Flex align="baseline">
<PlaceHolder className="inline" />
<PlaceHolder className="inline small" />
<PlaceHolder className="inline" />
</Flex>
</div>
);
ReactDOM.render(<FlexExample />, mountNode);
.flex-container {
margin: 0 15px;
}
.flex-container .inline {
width: 80px!important;
margin: 9px 9px 9px 0;
}
.flex-container .small {
height: 20px!important;
line-height: 20px!important;
}
.sub-title {
color: #888;
font-size: 14px;
padding: 30px 0 18px 0;
}
.placeholder {
background-color: #ebebef;
color: #bbb;
text-align: center;
height: 30px;
line-height: 30px;
width: 100%;
}
API
Flex
属性 | 说明 | 类型 | 默认值 |
---|
direction | 项目定位方向,值可以为 row ,row-reverse ,column ,column-reverse , RN 仅支持row ,column | String | row |
wrap | 子元素的换行方式,可选nowrap ,wrap ,wrap-reverse , RN 仅支持nowrap ,wrap | String | nowrap |
justify | 子元素在主轴上的对齐方式,可选start ,end ,center ,between ,around | String | start |
align | 子元素在交叉轴上的对齐方式,可选start ,center ,end ,baseline ,stretch RN仅支持start ,end ,center ,stretch | String | center |
alignContent | 有多根轴线时的对齐方式,可选start ,end ,center ,between ,around ,stretch | String | stretch |
Flex.Item
Flex.Item 组件默认加上了样式flex:1
,保证所有 item 平均分宽度, Flex 容器的 children 不一定是 Flex.Item