自动获取屏幕尺寸信息的html文件

html 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>自动获取屏幕尺寸信息的html文件</title>
    <style>
        #testDiv {
            width: 100%;
            height: 100vh; /* 100% of the viewport height */
            background-color: lightblue;
            text-align: center;
            font-size: 2em;
            display: flex;
            justify-content: center;
            align-items: center;
        }
    </style>
</head>
<body>
    <div id="testDiv">
        宽度: <span id="width"></span>px, 高度: <span id="height"></span>px
    </div>

    <script>
        function updateSize() {
            const div = document.getElementById('testDiv');
            const width = div.offsetWidth;
            const height = div.offsetHeight;
            document.getElementById('width').textContent = width;
            document.getElementById('height').textContent = height;
        }

        window.onload = updateSize;
        window.onresize = updateSize;
    </script>
</body>
</html>
相关推荐
布列瑟农的星空9 分钟前
Playwright使用体验
前端·单元测试
卤代烃40 分钟前
🦾 可为与不可为:CDP 视角下的 Browser 控制边界
前端·人工智能·浏览器
_XU1 小时前
AI工具如何重塑我的开发日常
前端·人工智能·深度学习
C_心欲无痕1 小时前
vue3 - defineExpose暴露给父组件属性和方法
前端·javascript·vue.js·vue3
鹿人戛1 小时前
HarmonyOS应用开发:相机预览花屏问题解决案例
android·前端·harmonyos
萌萌哒草头将军2 小时前
绿联云 NAS 安装 AudioDock 详细教程
前端·docker·容器
贺今宵2 小时前
安装better-sqlite3报错electron-vite
javascript·sql·sqlite·sqlite3
GIS之路2 小时前
GIS 数据转换:使用 GDAL 将 GeoJSON 转换为 Shp 数据
前端
2501_944446002 小时前
Flutter&OpenHarmony文件夹管理功能实现
android·javascript·flutter
朴shu3 小时前
Luckysheet 远程搜索下拉 控件开发 : 揭秘二开全流程
前端