怎么做适配
1.媒体查询 + rem(通过媒体查询更改html根字体大小,实现字体大小随屏幕尺寸变化)
@media screen and (max-width:320px){
html{
font-size:12px;
}
}
@media screen and (min-width:321px) and (max-width:375px){
html{
font-size:14px;
}
}
@media screen and (min-width:376px){
html{
font-size:16px;
}
}
2.vw + vh + rem(响应式布局vw+vh+rem屏幕适配方案)
1先设置根元素为100px=1rem
2然后算100vw=所少px
3.然后算出100px=多少vw
如果设计图为 640px html设置{font-size:31.25vw}
如果设计图为 750px html设置{font-size:26.67vw}
3 (https://blog.csdn.net/weixin_42350305/article/details/117955220)
document.documentElement.style.fontSize=(document.documentElement.clientWidth/750)*100+'px';
监听窗口改变设置rem
window.addEventlistener('resize',fn);
4 插件 (https://blog.csdn.net/weixin_43932309/article/details/125102930 和 https://www.bilibili.com/video/BV1Zm4y1j75e/spm_id_from=333.337.searchcard.all.click&vd_source=d5a2dcad2c91b804d2d7052801c7c3d0)
移动端rem适配布局:Vue+amfe-flexible+postcss-pxtorem
- npm install amfe-flexible --save
npm install postcss-pxtorem --save - main.js中导入amfe-flexible; import 'amfe-flexible'
- vue.config.js文件配置(vue-cli3)
const pxtorem = require('postcss-pxtorem')
module.exports = {
css: {
extract: { ignoreOrder: true },
loaderOptions:{
postcss: {
plugins: [
pxtorem({
rootValue: 37.5, // UI图宽的十分之一
propList: ['*']
})
]
}
}
}
};
参考文献: https://blog.csdn.net/qq_48294048/article/details/127248331
https://blog.csdn.net/weixin_43294560/article/details/103997290
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了