mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-19 06:43:16 +08:00
docs: supplement px2rem
docs (#43594)
* docs: supplement `px2rem` docs * chore: update
This commit is contained in:
parent
d178eee50a
commit
b76a322f9f
@ -71,3 +71,53 @@ When toggled, styles will downgrade CSS logical properties:
|
||||
++ left: 0;
|
||||
}
|
||||
```
|
||||
|
||||
### Rem Adaptation
|
||||
|
||||
In responsive web development, there is a need for a convenient and flexible way to achieve page adaptation and responsive design. The `px2remTransformer` transformer can quickly and accurately convert pixel units in style sheets to rem units relative to the root element (HTML tag), enabling the implementation of adaptive and responsive layouts.
|
||||
|
||||
```tsx
|
||||
import { StyleProvider, px2remTransformer } from '@ant-design/cssinjs';
|
||||
|
||||
const px2rem = px2remTransformer({
|
||||
rootValue: 32, // 32px = 1rem; @default 16
|
||||
});
|
||||
|
||||
export default () => (
|
||||
<StyleProvider transformers={[px2rem]}>
|
||||
<MyApp />
|
||||
</StyleProvider>
|
||||
);
|
||||
```
|
||||
|
||||
The resulting transformed styles:
|
||||
|
||||
```diff
|
||||
.px2rem-box {
|
||||
- width: 400px;
|
||||
+ width: 12.5rem;
|
||||
background-color: green;
|
||||
- font-size: 32px;
|
||||
+ font-size: 1rem;
|
||||
border: 10PX solid #f0f;
|
||||
}
|
||||
|
||||
@media only screen and (max-width: 600px) {
|
||||
.px2rem-box {
|
||||
background-color: red;
|
||||
- margin: 10px;
|
||||
+ margin: 0.3125rem;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Options
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
| Parameter | Description | Type | Default |
|
||||
| --- | --- | --- | --- |
|
||||
| rootValue | Font size of the root element | `number` | 16 |
|
||||
| precision | Decimal places for the converted value | `number` | 5 |
|
||||
| mediaQuery | Whether to convert px in media queries | `boolean` | false |
|
||||
|
||||
For more details, please refer to: [px2rem.ts#Options](https://github.com/ant-design/cssinjs/blob/master/src/transformers/px2rem.ts)
|
||||
|
@ -71,3 +71,53 @@ export default () => (
|
||||
++ left: 0;
|
||||
}
|
||||
```
|
||||
|
||||
### rem 适配
|
||||
|
||||
在响应式网页开发中,需要一种方便且灵活的方式来实现页面的适配和响应式设计。`px2remTransformer` 转换器可以快速而准确地将样式表中的像素单位转换为相对于根元素(HTML 标签)的 rem 单位,实现页面的自适应和响应式布局。
|
||||
|
||||
```tsx
|
||||
import { StyleProvider, px2remTransformer } from '@ant-design/cssinjs';
|
||||
|
||||
const px2rem = px2remTransformer({
|
||||
rootValue: 32, // 32px = 1rem; @default 16
|
||||
});
|
||||
|
||||
export default () => (
|
||||
<StyleProvider transformers={[px2rem]}>
|
||||
<MyApp />
|
||||
</StyleProvider>
|
||||
);
|
||||
```
|
||||
|
||||
最终转换后的样式:
|
||||
|
||||
```diff
|
||||
.px2rem-box {
|
||||
- width: 400px;
|
||||
+ width: 12.5rem;
|
||||
background-color: green;
|
||||
- font-size: 32px;
|
||||
+ font-size: 1rem;
|
||||
border: 10PX solid #f0f;
|
||||
}
|
||||
|
||||
@media only screen and (max-width: 600px) {
|
||||
.px2rem-box {
|
||||
background-color: red;
|
||||
- margin: 10px;
|
||||
+ margin: 0.3125rem;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 配置项
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
| 参数 | 说明 | 类型 | 默认值 |
|
||||
| --- | --- | --- | --- |
|
||||
| rootValue | 根元素字体大小 | `number` | 16 |
|
||||
| precision | 转换后的小数点位数 | `number` | 5 |
|
||||
| mediaQuery | 是否转换媒体查询中的 px | `boolean` | false |
|
||||
|
||||
详细请参考: [px2rem.ts#Options](https://github.com/ant-design/cssinjs/blob/master/src/transformers/px2rem.ts)
|
||||
|
Loading…
Reference in New Issue
Block a user