如何使用 CSS 拉伸元素以适应浏览器窗口的整个高度?

cssweb developmentfront end technology更新于 2025/12/8 3:56:17

要使用 CSS 拉伸元素以适应浏览器窗口的整个高度,代码如下 −

示例

<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style>
   *{
      box-sizing: border-box;
   }
   html, body {
      height: 100%;
      margin: 0;
   }
   .fullHeight{
      font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
      height: 100%;
      background: rgb(135, 27, 207);
      color:white;
      font-size: 40px;
      padding: 40px;
   }
</style>
</head>
<body>
<div class="fullHeight">This div element will stretch to the whole height and width of the
window</div>
</body>
</html>

输出

上述代码将产生以下输出 −


相关文章


有用资源