zoukankan      html  css  js  c++  java
  • 移动端——处理rem根字体

    在入口js文件写入以下方法:

    /*处理rem根字体 start*/
    
    // 基准大小
    const baseSize = 32
    // 设置 rem 函数
    function setRem() {
      // 当前页面宽度相对于 750 宽的缩放比例,可根据自己需要修改。
      const scale = document.documentElement.clientWidth / 750
      // 设置页面根节点字体大小
      document.documentElement.style.fontSize = (baseSize * Math.min(scale, 2)) + 'px'
    }
    // 初始化
    setRem()
    // 改变窗口大小时重新设置 rem
    window.onresize = function () {
      setRem()
    }
    /*处理rem根字体 end*/

    引入公用css

    $browser-default-font-size: 16px !default;
    @function pxTorem($px) {
      //$px为需要转换的字号
      @if (unitless($px)) {
        @return pxTorem($px + 0px);
      } @else if (unit($px) == em) {
        @return $px;
      }
      @return ($px / $browser-default-font-size) * 1rem;
    }

    在使用时直接

    .title {           
      margin-bottom
    : pxTorem(18);   padding: 0 pxTorem(20);   img {     height: pxTorem(31);     width: pxTorem(31);   } }

    按照常规UI设计图时,如果是px单位,传到pxTorem的除以2,pt单位时,直接按照原来的数值即可

  • 相关阅读:
    SpringMVC详解
    java设计模式
    运行时异常与一般异常区别
    oracle基本操作大全
    get post 区别
    hibernate
    Spring框架
    http和https
    JDBC详解
    (转)Entity Framework4.1实现动态多条件查询、分页和排序
  • 原文地址:https://www.cnblogs.com/yixiancheng/p/12048216.html
Copyright © 2011-2022 走看看