HarmonyOS 华为浏览器是否会支持rem的自适应方案

HarmonyOS
2024-12-23 16:38:56
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
aquaa

参考:

<!DOCTYPE html>
  <html lang="en">
  <head>
  <meta charset="utf-8">
  <title>FengHuang</title>
  <meta name="viewport" content="initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no,width=device-width,viewport-fit=cover">
  <style>
  body, html {
  max-width: 100%;
}
html {
  background-color: #FFFFFF;
  padding: 0;
}
body {
  background-color: #CCCCCC;
  margin: 0;
  padding: 0;
}
#info {
  width: 100%;
  box-sizing: border-box;
  padding: 20px 10px;
  background-color: #999999;
  color: #FFFFFF;
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
}
html,body {margin: 0 auto;}
#blocks {
  color: #ffffff;
  line-height: 1rem;
  vertical-align: middle;
  text-align: center;
}
.full-block {
  width: 10rem;
  height: 1rem;
  background-color: blue;
  font-size: 0.5rem;
  margin-bottom: 2px;
  white-space: nowrap;
}
.half-block {
  width: 5rem;
  height: 1rem;
  background-color: green;
  font-size: 0.25rem;
  margin-bottom: 2px;
  white-space: nowrap;
}
</style>
  </head>
  <body>
  <div id="info"></div>
  <div id="blocks">
  <div class="full-block">W:10rem, H: 1rem, F: 0.5rem</div>
  <div class="full-block" style="font-size: 18.75px;">W:10rem, H: 1rem, F: 18.75px</div>
  <div class="half-block">W:5rem, H: 1rem, F: 0.25rem</div>
  <div class="half-block" style="font-size: 9.375px;">W:5rem, H: 1rem, F: 9.375px</div>
  </div>
  </body>
  <script>
  function showWidthInfo() {
    const infoDom = document.getElementById('info');
    const htmlStr = `
            window.devicePixelRatio: ${window.devicePixelRatio}<br/>
            visualViewport.scale: ${visualViewport.scale}<br/>
            document.documentElement.clientWidth: ${document.documentElement.clientWidth}<br/>
            document.documentElement.offsetWidth: ${document.documentElement.offsetWidth}<br/>
            document.documentElement.scrollWidth: ${document.documentElement.scrollWidth}<br/>
            window.outerWidth: ${window.outerWidth}<br/>
            window.innerWidth: ${window.innerWidth}<br/>
            window.screen.width: ${window.screen.width}<br/>
            document.documentElement.clientHeight: ${document.documentElement.clientHeight}<br/>
            document.documentElement.offsetHeight: ${document.documentElement.offsetHeight}<br/>
            document.documentElement.scrollHeight: ${document.documentElement.scrollHeight}<br/>
            document.documentElement.style.fontSize: ${document.documentElement.style.fontSize}<br/>
        `;
    infoDom.innerHTML = htmlStr;
  }

function rem() {
  function resize() {
    var width = window.innerWidth;
    var rem = width / 10;
    document.documentElement.style.fontSize = rem + 'px';
    showWidthInfo()
  }
  resize()
  window.addEventListener('resize', resize)
}

document.addEventListener('DOMContentLoaded', function () {
  showWidthInfo();
  rem();
})
  </script>
  </html>
  <!DOCTYPE html>
  <html lang="en">
  <head>
  <meta charset="utf-8">
  <title>FengHuang</title>
  <meta name="viewport" content="initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no,width=device-width,viewport-fit=cover">
  <style>
  body, html {
  max-width: 100%;
}
html {
  background-color: #FFFFFF;
  padding: 0;
}
body {
  background-color: #CCCCCC;
  margin: 0;
  padding: 0;
}
#info {
  width: 100%;
  box-sizing: border-box;
  padding: 20px 10px;
  background-color: #999999;
  color: #FFFFFF;
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
}
html,body {margin: 0 auto;}
#blocks {
  color: #ffffff;
  line-height: 1rem;
  vertical-align: middle;
  text-align: center;
}
.full-block {
  width: 10rem;
  height: 1rem;
  background-color: blue;
  font-size: 0.5rem;
  margin-bottom: 2px;
  white-space: nowrap;
}
.half-block {
  width: 5rem;
  height: 1rem;
  background-color: green;
  font-size: 0.25rem;
  margin-bottom: 2px;
  white-space: nowrap;
}
</style>
  </head>
  <body>
  <div id="info"></div>
  <div id="blocks">
  <div class="full-block">W:10rem, H: 1rem, F: 0.5rem</div>
  <div class="full-block" style="font-size: 18.75px;">W:10rem, H: 1rem, F: 18.75px</div>
  <div class="half-block">W:5rem, H: 1rem, F: 0.25rem</div>
  <div class="half-block" style="font-size: 9.375px;">W:5rem, H: 1rem, F: 9.375px</div>
  </div>
  </body>
  <script>
  function showWidthInfo() {
    const infoDom = document.getElementById('info');
    const htmlStr = `
            window.devicePixelRatio: ${window.devicePixelRatio}<br/>
            visualViewport.scale: ${visualViewport.scale}<br/>
            document.documentElement.clientWidth: ${document.documentElement.clientWidth}<br/>
            document.documentElement.offsetWidth: ${document.documentElement.offsetWidth}<br/>
            document.documentElement.scrollWidth: ${document.documentElement.scrollWidth}<br/>
            window.outerWidth: ${window.outerWidth}<br/>
            window.innerWidth: ${window.innerWidth}<br/>
            window.screen.width: ${window.screen.width}<br/>
            document.documentElement.clientHeight: ${document.documentElement.clientHeight}<br/>
            document.documentElement.offsetHeight: ${document.documentElement.offsetHeight}<br/>
            document.documentElement.scrollHeight: ${document.documentElement.scrollHeight}<br/>
            document.documentElement.style.fontSize: ${document.documentElement.style.fontSize}<br/>
        `;
    infoDom.innerHTML = htmlStr;
  }

function rem() {
  function resize() {
    var width = window.innerWidth;
    var rem = width / 10;
    document.documentElement.style.fontSize = rem + 'px';
    showWidthInfo()
  }
  resize()
  window.addEventListener('resize', resize)
}

document.addEventListener('DOMContentLoaded', function () {
  showWidthInfo();
  rem();
})
  </script>
  </html>
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116.
  • 117.
  • 118.
  • 119.
  • 120.
  • 121.
  • 122.
  • 123.
  • 124.
  • 125.
  • 126.
  • 127.
  • 128.
  • 129.
  • 130.
  • 131.
  • 132.
  • 133.
  • 134.
  • 135.
  • 136.
  • 137.
  • 138.
  • 139.
  • 140.
  • 141.
  • 142.
  • 143.
  • 144.
  • 145.
  • 146.
  • 147.
  • 148.
  • 149.
  • 150.
  • 151.
  • 152.
  • 153.
  • 154.
  • 155.
  • 156.
  • 157.
  • 158.
  • 159.
  • 160.
  • 161.
  • 162.
  • 163.
  • 164.
  • 165.
  • 166.
  • 167.
  • 168.
  • 169.
  • 170.
  • 171.
  • 172.
  • 173.
  • 174.
  • 175.
  • 176.
  • 177.
  • 178.
  • 179.
  • 180.
  • 181.
  • 182.
  • 183.
  • 184.
  • 185.
  • 186.
  • 187.
  • 188.
  • 189.
  • 190.
  • 191.
  • 192.
  • 193.
  • 194.
  • 195.
  • 196.
  • 197.
  • 198.
  • 199.
  • 200.
分享
微博
QQ
微信
回复
2024-12-23 19:02:04
相关问题
Web组件是否支持浏览器localstorage?
1635浏览 • 1回复 待解决
HarmonyOS 启动默认浏览器
1525浏览 • 1回复 待解决
浏览器应用应该怎样拉起?
1205浏览 • 2回复 待解决
HarmonyOS webview浏览器获取定位异常
959浏览 • 1回复 待解决
HarmonyOS 如何在浏览器唤起app
1714浏览 • 1回复 待解决
浏览器下载文件如何导入鸿蒙
8585浏览 • 1回复 待解决
HarmonyOS 浏览器内无法下载charles证书
1093浏览 • 1回复 待解决
HarmonyOS applink从浏览器跳转到应用
1256浏览 • 1回复 待解决
HarmonyOS浏览器scheme链接唤起APP问题
2126浏览 • 1回复 待解决
HarmonyOS 浏览器真机调试问题
800浏览 • 1回复 待解决