absolute-center
#
插件名absolute-center
#
安装- npm
- Yarn
npm install @jswork/styled-plugin-absolute-center
yarn add @jswork/styled-plugin-absolute-center
#
参数名称 | 类型 | description |
---|---|---|
value | string | 是否为水平/垂直居中(x/y/xy) |
绝对居中的一种实现方式。
#
原理note
- margin: auto
- 上/下/左/右 均为 0
- 适用于被居中的元素,自身是有 width/height 的
#
用法仅 X 方向居中
<View plugin="absolute-center:x"> <div style={{width: 200, height: 400}}>我是要被居中的 element</div></View>
仅 Y 方向居中
<View plugin="absolute-center:y"> <div style={{width: 200, height: 400}}>我是要被居中的 element</div></View>
XY 方向居中
<View plugin="absolute-center:xy"> <div style={{width: 200, height: 400}}>我是要被居中的 element</div></View>
#
演示Live Editor
Result
SyntaxError: Unexpected token (1:8) 1 : return () ^