自动获取屏幕尺寸信息的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>
相关推荐
xiaokuangren_27 分钟前
前端css颜色
前端·css
Huanzhi_Lin29 分钟前
关于V8/MajorGC/MinorGC——性能优化
javascript·性能优化·ts·js·v8·新生代·老生代
hoiii1871 小时前
C# 基于 LumiSoft 实现 SIP 客户端方案
前端·c#
anOnion1 小时前
构建无障碍组件之Meter Pattern
前端·html·交互设计
小码哥_常1 小时前
Spring Boot配置diff:解锁配置管理新姿势
前端
小码哥_常1 小时前
告别onActivityResult!Android数据回传的3大痛点与终极解决方案
前端
hhcccchh2 小时前
1.2 CSS 基础选择器、盒模型、flex 布局、grid 布局
前端·css·css3
修己xj2 小时前
Markdown 里写公式,别只知道 LaTeX!试试 HTML 标签,简单到飞起
html
专吃海绵宝宝菠萝屋的派大星3 小时前
使用Dify对接自己开发的mcp
java·服务器·前端
爱分享的阿Q3 小时前
Rust加WebAssembly前端性能革命实践指南
前端·rust·wasm