为什么内容以100%的宽度消失

Why my .topnav, .mainnav and my .content divs the content escapes them?

从行跳到页数限制时,我该如何做?

它们已经是100%的宽度

* {
  list-style: none;
  text-decoration: none;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
}

.container {
  display: grid;
  grid-template-columns: 280px 1fr;
  width: 100%;
  height: 100%;
  position: fixed;
}

.leftbar {
  background: #1D2126;
  height: 100%;
  width: 100%;
  grid-template-rows: 100px 1fr;
}

.rightbar {
  display: grid;
  grid-template-rows: 100px 1fr;
  width: calc(100%-280px);
  height: 100%;
  position: fixed;
  margin-left: 280px;
}

.header {
  display: grid;
  grid-template-rows: 30px 70px;
  width: 100%;
  height: 100%;
}

.topnav {
  background: #1A1E23;
}

.mainnav {
  background: #1D2126;
}

.content {
  background: #21252B;
  overflow-y: scroll;
}
<div class="container">
  <div class="leftbar">
    <div class="logo"><img src="https://www.csgoroll.com/en/assets/logo.png" width="80%"></div>
    <div class="chat">
      <div class="chatbox">

      </div>
      <div class="chatsend">

      </div>
    </div>
  </div>
  <div class="rightbar">
    <div class="header">
      <div class="topnav">aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</div>
      <div class="mainnav">d</div>
    </div>
    <div class="content">
      asdaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaassssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
    </div>
  </div>
</div>
评论
贪婪的想念
贪婪的想念

您有两个原因:

首先,您有一个无尽的文本,以“ aaaa”开头,因此,如果您不破坏文本(使用空格或使用CSS),则布局将紧随文本之后

Second when using the calc() function in CSS, with addition and subtraction, it is mandatory to leave spaces around the operator, so instead of width: calc(100%-280px); you need to have width: calc(100% - 280px);

* {
  list-style: none;
  text-decoration: none;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
}

.container {
  display: grid;
  grid-template-columns: 280px 1fr;
  width: 100%;
  height: 100%;
  position: fixed;
}

.leftbar {
  background: #1D2126;
  height: 100%;
  width: 100%;
  grid-template-rows: 100px 1fr;
}

.rightbar {
  display: grid;
  grid-template-rows: 100px 1fr;
  width: calc(100% - 280px);
  height: 100%;
  position: fixed;
  margin-left: 280px;
}

.header {
  display: grid;
  grid-template-rows: 30px 70px;
  width: 100%;
  height: 100%;
}

.topnav {
  background: #1A1E23;
}

.mainnav {
  background: #1D2126;
}

.content {
  background: #21252B;
  overflow-y: scroll;
}
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title></title>
  <link rel="stylesheet" href="main.css">
</head>

<body>
  <div class="container">
    <div class="leftbar">
      <div class="logo"><img src="https://www.csgoroll.com/en/assets/logo.png" width="80%"></div>
      <div class="chat">
        <div class="chatbox">

        </div>
        <div class="chatsend">

        </div>
      </div>
    </div>
    <div class="rightbar">
      <div class="header">
        <div class="topnav">aaaa</div>
        <div class="mainnav">d</div>
      </div>
      <div class="content">aaaa
      </div>
    </div>
  </div>
</body>

</html>
点赞
评论