Skip to content

Rem 转 px 预设 ​

为所有工具将 rem 转换为 px。

源代码

安装 ​

bash
pnpm add -D @unocss/preset-rem-to-px
bash
yarn add -D @unocss/preset-rem-to-px
bash
npm install -D @unocss/preset-rem-to-px
bash
bun add -D @unocss/preset-rem-to-px
uno.config.ts
ts
import presetRemToPx from '@unocss/preset-rem-to-px'
import { defineConfig } from 'unocss'

export default defineConfig({
  presets: [
    presetRemToPx(),
    // ...其他预设
  ],
})

用法 ​

html
<div class="m-2"></div>
css
.m-2 {
  margin: 0.5rem;
}
css
.m-2 {
  margin: 8px;
}

选项 ​

baseFontSize ​

  • 类型: number
  • 默认: 16

用于将 rem 转换为 px 的基本字体大小(1rem = n px)。