Flex Flex布局
Flex 是 CSS 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 = () => (
<div className="flex-container">
<div className="sub-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="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">轴对齐方式</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 0.30rem;
}
.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;
}
.sub-title {
color: #888;
font-size: .28rem;
padding: 30px 0 18px 0;
}
```
API
适用平台:WEB、React-Native
Flex
属性 | 说明 | 类型 | 默认值 |
---|
direction | how flex items are placed in the flex container,value could be 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(web only ) | 有多根轴线时的对齐方式,可选start ,end ,center ,between ,around ,stretch | String | stretch |
Flex.Item
Flex.Item 组件默认加上了样式flex:1
,保证所有 item 平均分宽度, Flex 容器的 children 不一定是 Flex.Item