CSS 将div撑满body

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>测试</title>
  <style>
    html,
    body {
      height: 100%;
      margin: 0;
      overflow: hidden;
    }

    .container {
      height: calc(100% - 30px);
      width: calc(100% - 30px);
      margin: 15px;
      border: 1px solid red;
      overflow: auto;
    }
  </style>
</head>

<body>
  <div class="container">
    1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>

  </div>
</body>

</html>

 

posted @ 2023-10-10 09:32  缤纷世界  阅读(18)  评论(0编辑  收藏  举报