
$device-width: 1920px;
$device-height: 1080px;
@use "sass:math";
// 单位为px的高度转换为vh
// (100 / 1080) * height;
@function px2vh($size: 100px) {
    @if (type-of($size)=="number" and unit($size)=="px") {
        $height: 100vh;
        @return math.div($height, $device-height) * $size
    }
    @else {
        @return $size;
    }
}

// 单位为px的宽度转换为vw
// (100 / 1920) * width;
@function px2vw($size: 100px) {
    @if (type-of($size)=="number" and unit($size)=="px") {
        $width: 100vw;
        $result: math.div($width, $device-width) * $size;
        @return $result
    }
    @else {
        @return $size;
    }
}

// 单位为px的宽度转换为rem
@function px2rem($size: 16px) {
    // 根字体大小默认为16px
    @if (type-of($size)=="number" and unit($size)=="px") {
        @return math.div($size, 16px) * 1rem;
    }
    @else {
        @return $size;
    }
}


