HTML 屏幕高度属性
HTML 屏幕高度属性返回用户屏幕的总高度。
语法
以下是语法 −
screen.height
示例
让我们看一个 HTML 屏幕高度属性的示例 -
<!DOCTYPE html>
<html>
<style>
body {
color: #000;
height: 100vh;
background-color: #FBAB7E;
background-image: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%);
text-align: center;
}
.btn {
background: #db133a;
border: none;
height: 2rem;
border-radius: 2px;
width: 40%;
display: block;
color: #fff;
outline: none;
cursor: pointer;
margin: 1rem auto;
}
.show {
font-size: 1.2rem;
margin: 1rem auto;
font-weight: bold;
font-family: sans-serif;
}
</style>
<body>
<h1>HTML screen height Property</h1>
<button class="btn" onclick="get()">Show Screen Height</button>
<div class="show"></div>
<script>
function get() {
document.querySelector(".show").innerHTML = "Total height is " + screen.height + "px";
}
</script>
</body>
</html>输出

单击“显示屏幕高度”按钮以显示用户屏幕的总高度 −

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP