正在回答 回答被采纳积分+1
8回答
陈立天
2020-08-26 16:22:37
<!DOCTYPE html> <html> <head> <title>通用适配原理自由编程</title> <meta charset='utf-8' /> <meta name="viewport" content="width=device-width,initial-scale=1,maximun-scale=1,minmum-scale=1,user-scalable=no" /> <style lang="css"> * { margin: 0; padding: 0; box-sizing: border-box; } html,body { width: 100%; height: 100%; } img { width: 100%; height: 100%; vertical-align: top; } /*设计稿750px header高度100px*/ /* 1rem = font-size = 750 / 18.75 = 40,则100px = 100/40 = 2.5rem */ /* 在375px的屏幕下,header高度是50px 50/20 = 2.5rem */ .header-container { width: 100%; height: 2.5rem; background: #666; display: flex; align-items: center; justify-content: space-between; padding: 0 0.25rem ; } .header-logo { width: 5rem; height: 2rem; } .header-download { width: 4rem; height: 2rem; border-radius: 1rem; background: rgba(242,149,242,0.9); color: #000; text-align: center; font-size: 12px; display: flex; align-items: center; justify-content: center; } [data-dpr = "2"] .header-download { font-size:24px; font-size: 24px; height: 10px; } [data-dpr = "3"] .header-download { font-size:36px; } </style> </head> <body> <header class="header-container"> <div class="header-logo"> <img src="./img/logo.png" alt="慕课网"> </div> <div class="header-download"> 下载APP </div> </header> <script> (function() { 'use strict'; var docEl = document.documentElement; var maxWidth = 540; var minWidth = 320; //根据dpr动态设置meta缩放 var dpr = window.devicePixelRatio || 1; var viewportEl = document.querySelector('meta[name="viewport"]'); dpr = dpr >=3 ? 3 : (dpr >= 2 ? 2 : 1); docEl.setAttribute('data-dpr',dpr); docEl.setAttribute('max-width',maxWidth); docEl.setAttribute('min-widht',minWidth); var scale = 1/dpr; var content = 'width=device-width,initial-scale='+scale+',maximun-scale='+scale+',minmum-scale='+scale+',user-scalable=no'; if(viewportEl) { viewportEl.setAttribute('content',content); }else { viewportEl.createElement('meta'); viewportEl.setAttribute('name','viewport'); viewportEl.setAttribute('content',content); document.head.appendChild(viewportEl); } //动态设置html的font-size setRemUnit(); window.addEventListener('resize',setRemUnit); function setRemUnit(){ var ratio = 18.75; var viewWidth = docEl.getBoundingClientRect().width || window.innerWidth; if(maxWidth && (viewWidth/dpr > maxWidth)) { viewWidth = maxWidth; }else if(minWidth && (viewWidth/dpr < minWidth)) { viewWidth = minWidth; } docEl.style.fontSize = viewWidth / ratio + 'px'; } })(); </script> </body> </html>
3.WebAPP开发与小程序
- 参与学习 人
- 提交作业 622 份
- 解答问题 6815 个
微信带火了小程序,也让前端工程师有了更多的展现机会,本阶段带你从移动基础知识的学习到webAPP开发,及小程序开发,让你PC端与移动端两端通吃。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星