前端字体大小自适应

媒体(@media)查询:

pc:

html {font-size: 62.5%!important; /* 10÷16=62.5% */}
@media only screen and (min-width: 481px){
    html {
        font-size: 94%!important; /* 15.04÷16=94% */
    }
}
@media only screen and (min-width: 561px){
    html {
        font-size: 109%!important; /* 17.44÷16=109% */
    }
}
@media only screen and (min-width: 641px){
    html {
        font-size: 125%!important; /* 20÷16=125% */
    }
}

app:

@media only screen and (min-width: 320px){html {font-size: 62.5%!important;}}
@media only screen and (min-width: 360px){html {font-size: 72.5%!important;}}
@media only screen and (min-width: 400px){html {font-size: 82.5%!important;}}
@media only screen and (min-width: 480px){html {font-size: 94%!important;}}
echarts图表:
// 根据屏幕分辨率计算大小
const transformFontSize = (fontSize) => {
  const width = window.screen.width
  const ratio = width / 1920
  return parseInt(fontSize * ratio)
}
// 图表option里调用函数
series: [
        {
          name: '',
          type: 'pie',
          radius: ['35%', '35%'],
          itemStyle: {
            normal: {
              label: {
                show: true,
                position: 'outside',
                fontSize: transformFontSize(14),
                color: '#ddd',
              }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。