Flex Flex布局
Flex 是 Flexible Box 的缩写,意为"弹性布局",用来为盒状模型提供最大的灵活性。
如果不熟悉推荐学习下这个 Flex 布局教程## 代码演示
示例集合
import { Flex, WhiteSpace } from 'antd-mobile';
const PlaceHolder = (props) => (
<div style={{
backgroundColor: '#ebebef',
color: '#bbb',
textAlign: 'center',
height: '0.6rem',
lineHeight: '0.6rem',
width: '100%',
}} {...props}
>Item</div>
);
const FlexExample = React.createClass({
render() {
return (
<div className="flex-container">
<div className="title">基本</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="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="title">轴对齐方式</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 {
padding: 0.18rem;
}
.flex-container .title {
color: #888;
margin: 0.20rem 0;
}
.flex-container .inline {
width: 1.6rem!important;
margin: 0.18rem 0.18rem 0.18rem 0;
}
.flex-container .small {
height: 0.4rem!important;
line-height: 0.4rem!important;
}
```
API ( 适用平台:WEB、React-Native )
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/top ,center/middle ,end/bottom ,baseline ,stretch RN仅支持start ,end ,center ,stretch | String | center |
alignContent(web only ) | 有多根轴线时的对齐方式,可选start ,end ,center ,between ,around ,stretch | String | stretch |
Flex.Item
Flex.Item 组件默认加上了样式flex:1
,保证所有 item 平均分宽度, Flex 容器的 children 不一定是 Flex.Item