@unocss-applet/preset-rem-rpx
v0.8.5
Published
Coverts rem <=> rpx for utils.
Downloads
2,972
Readme
@unocss-applet/preset-rem-rpx
Coverts rem <=> rpx for utils.
Instal
npm i @unocss-applet/preset-rem-rpx --save-dev # with npm
yarn add @unocss-applet/preset-rem-rpx -D # with yarn
pnpm add @unocss-applet/preset-rem-rpx -D # with pnpm
Usage
import { defineConfig } from 'unocss'
import { presetRemRpx } from '@unocss-applet/preset-rem-rpx'
export default defineConfig({
presets: [
// ...
presetRemRpx({ baseFontSize: 16, screenWidth: 375, mode: 'rem2rpx' }),
],
})
⚠️If you change baseFontSize
other than 16
and use rpx2rem
mode, you need to set the corresponding root font-size
in H5.
Type Declarations
export interface RemRpxOptions {
/**
* 1rem = n px
* @default 16
*/
baseFontSize?: number
/**
* screen width in px
* @default 375
*/
screenWidth?: number
/**
* rem to rpx or rpx to rem
* @default 'rem2rpx'
*/
mode?: 'rem2rpx' | 'rpx2rem'
}
<div class="m-1rem p-32rpx"></div>
without
.m-1rem {
margin: 1rem;
}
.p-32rpx {
padding: 32rpx;
}
rem2rpx
.m-1rem {
margin: 32rpx;
}
.p-32rpx {
padding: 32rpx;
}
rpx2rem
.m-1rem {
margin: 1rem;
}
.p-32rpx {
padding: 1rem;
}
License
MIT License © 2022-PRESENT Neil Lee