当前位置:网站首页>rem适配方案
rem适配方案
2022-07-13 16:26:00 【JiuMeilove】
为什么要rem适配方案
- 让一些不能等比自适应的元素,达到当设备尺寸发生改变的时候,等比例适配当前设备
- 使用媒体查询根据不同设备按比例设置html的字体大小,然后页面袁术使用rem做尺寸单位,当html字体大小变化,元素尺寸也会发生变化,从而达到等比例缩放适配
rem实际开发适配方案
- 按照设计稿与设备宽度的比例动态设计并设置html根标签的font-size大小(媒体查询)
- css中,设计稿元素的宽,高,相对位置等取值,按照同等比例换算为rem为单位的值
动态设置html标签font-size大小
- 假设设计稿是750ox
- 假设我们把整个屏幕划分为15等份(划分标准不一,可能是20份也可以是10等份)
- 每一份作为html字体大小,这里就是50px
- 那么在320px设备的时候,字体大小为320/15就是21.33px
- 用我们页面元素的大小,除以不同的html字体大小会发现他们比例还是相同的
- 比如我们以750为标准设计稿
- 一个100100像素的页面元素在750屏幕下,就是100/50转换为rem就是2rem2rem比例是1比1
- 320屏幕下,html字体大小为21.33,则2rem=42.66px此时宽和高都是42.66但是宽和高的比例还是1比1
- 但是已经能实现不同屏幕下,页面元素盒子等比例缩放的效果
元素大小取值方法
- 最后公式:页面元素的rem值=页面元素值(px)/(屏幕宽度/划分的份数)
- 屏幕宽度/划分的份数就是html font-size的大小
- 或者:页面元素的rem值=页面元素(px)/html font -size字体的大小
边栏推荐
- Heavyweight new | shangsilicon Valley C4d 3D design practical tutorial release
- CarSim仿真快速入门(十一)—驾驶员模型(1)
- iMeta期刊部分文章被PubMed收录
- Put an object with corresponding field in the first one in the list
- Cf1526d kill Anton (violence)
- 胶带的模切工艺解析
- 微生物组-扩增子16S分析和可视化(2022.7本周开课)
- 微信小程序2-WXSS,WXS
- Compilation principle experiment IV LR (0) analysis method (automatic generation of Lr0 analysis table) complete code
- Select sort
猜你喜欢

Yuanye, Chief Strategic Officer of Shengye: in the era of industrial digitalization, connection is more important than ownership

Tear the source code of gateway by hand, and tear the source code of workflow and load balancing today

In depth analysis of kubernetes admission webhooks

微信小程序3-小程序生命周期和组件

CarSim仿真快速入门(十二)—驾驶员模型(2)

DCC888 :Instruction Level Parallelism

【论文笔记】基于深度强化学习的密集物体温度优先推抓方法

PreScan快速入门到精通第十五讲之道路元素

Vs code recommended plug-ins

【北京林业大学】考研初试复试资料分享
随机推荐
A gem enthusiast's strategy of building a station from scratch
PreScan快速入门到精通第十五讲之道路元素
从零实现一个日志框架
微生物组-扩增子16S分析和可视化(2022.7本周开课)
Tear the source code of gateway by hand, and tear the source code of workflow and load balancing today
ACW water pouring problem (search out all schemes)
The simple solution the boss wants vs. the needs the programmer understands | cartoon
【北京林业大学】考研初试复试资料分享
Vcenter6 vSphere failed to log in fault handling record
Excuse me, how much does it cost to open an account for flush stock speculation? Is it safe to open an account?
ASP. Net core foundation I
Put an object with corresponding field in the first one in the list
Pagebean introduction
[200 opencv routines] 228 Extendlbp improved operator of feature description
互联网对内核模块的加载之道
Qucs初步使用指南(不是multism)
CF1257F Make Them Similar(meet in the middle,模拟退火)
【论文笔记】基于 ROS 的送餐机器人自主抓取实现
Gui-pyqt5-initial 1
Research on kinematics of wire driven continuum robot using motion capture