移动端(阿里rem)布局
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <meta name="viewport" content="width=device-width, initial-scale=1 user-scalable=0"> <script> //通过window.screen.width获取屏幕的宽度 var offWidth = window.screen.width / 30; //这里用宽度/30表示1rem取得的px document.getElementsByTagName("html")[0].style.fontSize = offWidth + 'px'; //把rem的值复制给顶级标签html的font-size </script> <style> /*偷个懒就直接全局初始化了*/ * { padding: 0; margin: 0; } /* 布局需求,上下都间隔*/ div { margin: 0.833333333rem 0; } /* 去处a标签的下划线*/ a { text-decoration: none; } .one { width: 30rem; /*100/720*30*/ height: 4.166666667rem; /*图片宽750,高100*/ background: url("./img/1.jpg") no-repeat; background-size: contain; } .two { width: 30rem; /*400/720*30*/ height: 16.6666667rem; /*图片宽750,高400*/ background: url("./img/2.jpg") no-repeat; background-size: contain; } .three { width: 30rem; height: 5.875rem; /*图片宽750,高141*/ background: url("./img/3.jpg") no-repeat; background-size: contain; } .four { width: 28.33333333rem; height: 13.16666667rem; /*图片宽750,高316*/ background: url("./img/4.jpg") no-repeat; background-size: contain; margin-left: 0.833333333rem; position: relative; } span { position: absolute; display: block; width: 8.33333333rem; height: 2rem; line-height: 2rem; text-align: center; background: #fff; right: 0.833333333rem; bottom: 0.833333333rem; font-size: 0.95833333rem; color: red; cursor: pointer; } .five { width: 28.33333333rem; height: 13.16666667rem; /*图片宽750,高316*/ background: url("./img/top4.jpg") no-repeat; background-size: contain; margin-left: 0.833333333rem; } </style> </head> <body> <div class="one"></div> <div class="two"></div> <div class="three"></div> <div class="four"> <a href=""><span>25元起</span></a> </div> <div class="five"></div> </body> </html>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现