您需要使用JavaScript。要获取屏幕的宽度和高度,请执行以下操作:
<script>
var height = window.screen.height;
var width = window.screen.width;
</script>
要正确考虑更高分辨率的设备,如苹果的“视网膜”显示器,您需要将这些值乘以“像素比”:
<script>
var pixelRatio = window.devicePixelRatio;
var height = window.screen.height * pixelRatio;
var width = window.screen.width * pixelRatio;
</script>