h5 rem字体

本文介绍了一种响应式网页设计中针对不同屏幕尺寸自动调整字体大小的方法。通过使用CSS媒体查询,根据不同设备的最大宽度设置html及body元素的基础字体大小,确保了良好的跨设备阅读体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

@media only screen and (max-width: 1920px), only screen and (max-device-width: 1920px) {
    html,
    body {
      font-size: 512px;
    }
  }
@media only screen and (max-width: 1440px), only screen and (max-device-width: 1440px) {
    html,
    body {
      font-size: 384px;
    }
  }
@media only screen and (max-width: 1366px), only screen and (max-device-width: 1366px) {
    html,
    body {
      font-size: 364.267px;
    }
  }
@media only screen and (max-width: 1080px), only screen and (max-device-width: 1080px) {
    html,
    body {
      font-size: 288px;
    }
  }
  @media only screen and (max-width: 1024px), only screen and (max-device-width: 1024px) {
    html,
    body {
      font-size: 273.067px;
    }
  }
  @media only screen and (max-width: 960px), only screen and (max-device-width: 960px) {
    html,
    body {
      font-size: 256px;
    }
  }
  @media only screen and (max-width: 800px), only screen and (max-device-width: 800px) {
    html,
    body {
      font-size: 213.333px;
    }
  }
  @media only screen and (max-width: 750px), only screen and (max-device-width: 750px) {
    html,
    body {
      font-size: 200px;
    }
  }
  @media only screen and (max-width: 720px), only screen and (max-device-width: 720px) {
    html,
    body {
      font-size: 192px;
    }
  }
  @media only screen and (max-width: 640px), only screen and (max-device-width: 640px) {
    html,
    body {
      font-size: 170.667px;
    }
  }
  @media only screen and (max-width: 600px), only screen and (max-device-width: 600px) {
    html,
    body {
      font-size: 160px;
    }
  }
@media only screen and (max-width: 540px), only screen and (max-device-width: 540px) {
    html,
    body {
      font-size: 144px;
    }
  }
  @media only screen and (max-width: 480px), only screen and (max-device-width: 480px) {
    html,
    body {
      font-size: 128px;
    }
  }
  @media only screen and (max-width: 414px), only screen and (max-device-width: 414px) {
    html,
    body {
      font-size: 110.4px;
    }
  }
  @media only screen and (max-width: 400px), only screen and (max-device-width: 400px) {
    html,
    body {
      font-size: 106.6667px;
    }
  }
  @media only screen and (max-width: 375px), only screen and (max-device-width: 375px) {
    html,
    body {
      font-size: 100px;
    }
  }
  @media only screen and (max-width: 360px), only screen and (max-device-width: 360px) {
    html,
    body {
      font-size: 96px;
    }
  }
  @media only screen and (max-width: 320px), only screen and (max-device-width: 320px) {
    html,
    body {
      font-size: 85.3333px;
    }
  }

  body {
      font-size: 16px!important;
  }

 

!DOCTYPE html> <html 85.3333px;"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black"> <meta http-equiv="Cache-Control" content="no-transform"> <meta name="applicable-device" content="mobile"> <meta http-equiv="Cache-Control" content="no-siteapp"> <title>【元旦倒计时】2020新年倒计时_距离2020年还有多少天</title> <style> .timebox2{width:640px;background-color:#FCF3E2;padding: 1rem 0;background: url(images/ks_bcg2.png) center center no-repeat;background-size: 100% 100%;} .timebox2 div,timebox2 span,timebox2 div span{color: #333 !important;} .timebox2 .timecounter span{color: #333 !important;} .timetext{width: 100%;text-align: center;} .timetexttitle{font-size:0.3rem;margin-bottom: 10px;color: #fff;} .timetextintro{font-size: 0.22rem;margin-bottom: 10px;color: #fff;padding: 0 1.52rem;box-sizing: border-box;} .timecounter{font-size: 0.6rem;} .txt{padding: 0 0.2rem;box-sizing:border-box;} .clearbg5{display: block;clear: both;width: 100%;height: 0.16rem;overflow: hidden;background-color: #eee;} .txt p{line-height: 30px;margin-top: 0.2rem;} .txt p img{width: 100%;} .timecounter span{color: #fff;} </style> <body> 2020年元旦倒计时 元旦时间:2020年1月1日 农历腊月初七 星期三 目前距离2020年元旦还有 127 天 10 时 24 分 8 秒 [removed] function getRTime() { var EndTime = new Date("2020/01/01 00:00:00"); //截止时间 var NowTime = new Date(); var t = EndTime.getTime() - NowTime.getTime(); var d = Math.floor(t / 1000 / 60 / 60 / 24); var h = Math.floor(t / 1000 / 60 / 60 % 24); var m = Math.floor(t / 1000 / 60 % 60); var s = Math.floor(t / 1000 % 60); document.getElementById("t_d")[removed] = d + " 天"; document.getElementById("t_h")[removed] = h + " 时"; document.getElementById("t_m")[removed] = m + " 分"; document.getElementById("t_s")[removed] = s + " 秒"; } setInterval(getRTime, 1000); [removed] </body> </html>
### H5 REM 移动端网页适配方法 #### 使用REM进行移动端适配的优势 REM是一种相对单位,其相对于`<html>`根元素的字体大小而言。通过调整HTML标签内的font-size属性可以实现整个页面元素按比例缩放的效果[^2]。 #### 配置lib-flexible插件 对于Vue项目,在使用REM之前通常会先引入`lib-flexible`这个库来动态设置文档的基准字体大小。安装并配置该插件能够帮助自动计算不同屏幕宽度下的合理基础字号,从而简化后续开发工作中的样式编难度[^3]。 ```bash npm install lib-flexible --save ``` 接着在项目的入口文件(main.js)里导入此模块: ```javascript import 'lib-flexible' ``` #### 设置默认字体大小 为了让REM生效,还需要确保CSS中有如下定义,这一步骤是为了给定一个初始值以便其他地方基于它做进一步的比例转换: ```css html { font-size: 16px; /* 或者根据实际需求设定 */ } ``` #### 编响应式的CSS规则 当完成了上述准备工作之后就可以放心大胆地利用REM作为长度度量单位去构建灵活多变的设计了。下面是一个简单的例子展示了如何创建一个按钮组件,并让它的尺寸随着视窗变化而相应调整: ```scss .button { padding: .8rem; border-radius: .4rem; background-color: #ffeb3b; @media (min-width: 768px){ padding: 1.2rem; border-radius: .6rem; } } ``` #### 结合媒体查询优化体验 除了单纯依赖REM之外,还可以配合@media queries来做更细致入微的表现形式定制化处理。比如上面的例子中就额外增加了针对平板及以上设备的具体表现方式描述。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值