美文网首页
前端字体大小自适应

前端字体大小自适应

作者: 汶沐 | 来源:发表于2022-08-09 11:20 被阅读0次
媒体(@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',
              }

相关文章

网友评论

      本文标题:前端字体大小自适应

      本文链接:https://www.haomeiwen.com/subject/wrfdirtx.html