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
ts
// uno.config.ts
import { defineConfig } from 'unocss'
import presetRemToPx from '@unocss/preset-rem-to-px'

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)。

Released under the MIT License.