自动获取屏幕尺寸信息的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>
相关推荐
Martin -Tang2 分钟前
uniapp+vue3+ts自定义表格
javascript·vue.js·uni-app
问心无愧05138 分钟前
ctf show web入门 89
android·前端·笔记
hexu_blog8 分钟前
前端vue后端java+springboot如何显示视频压缩
前端·vue.js·vue压缩视频·java压缩视频·指定大小压缩视频
欧阳天风16 分钟前
electron播放本地音乐的问题
前端·javascript·electron
艾伦野鸽ggg19 分钟前
CSS布局与动效知识梳理
前端·css
介一安全21 分钟前
【漏洞学习】聊天机器人安全漏洞实战:服务器端JavaScript注入探秘
javascript·安全性测试·聊天机器人
ljt272496066123 分钟前
Vue笔记(二)--组件的属性和方法
前端·vue.js·笔记
Boop_wu24 分钟前
[前端] CSS 常用样式(聊天界面 / 网页布局专用)
前端·css·css3
声声codeGrandMaster25 分钟前
React框架的基础代码使用
前端·react.js·前端框架
叫我少年29 分钟前
Vue 3 集成 Vue Router:从基础配置到项目实践
前端·路由