• 物理像素


    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no" />
        <title></title>
        <style type="text/css">
            *{
                margin: 0;
                padding: 0;
            }
            #box{
                 8rem;
                height: 8rem;
                border: 1px solid #000000;
            }
        </style>
    </head>
    <body>
    <div id="box"></div>
    </body>
    <script type="text/javascript">
        var box = document.getElementById('box');
    
        //获取设备像素比
        var dpr = window.devicePixelRatio;
        //比例
        var scale = 1/dpr;
    
        //获取屏幕宽度 375
        var width = document.documentElement.clientWidth;
    
        //获取meta标签
        var metaNode = document.querySelector('meta[name="viewport"]')
        metaNode.setAttribute('content','width=device-width,initial-scale='+ scale +',user-scalable=no')
    
        //元素比例乘回来
        var htmlNode = document.querySelector('html');
        htmlNode.style.fontSize = width/16*dpr + 'px';
    
    </script>
    </html>
    

      

  • 相关阅读:
    索引有什么用?
    数据类型的优化策略?
    MySQL的锁策略有什么?
    行锁
    Innodb_lock_waits
    Innodb_locks表
    软件安装笔记
    Spring Boot学习笔记
    AI学习总结
    笔试面试题总结
  • 原文地址:https://www.cnblogs.com/queenDream/p/13476063.html
Copyright © 2020-2023  润新知