为什么我的.topnav
,.mainnav
和我的.content
div内容转义了它们?
当我达到行数上限时该怎么做?
它们已经是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>
您可以实现这样的滚动:
* {
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%;
overflow: scroll;
}
.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),则布局将跟随该文本
第二,在CSS中使用calc()
函数时,必须进行加减运算,因此必须在运算符周围留出空格,因此请使用width: calc(100%-280px);
代替您需要具有width: calc(100% - 280px);
查看下面的代码片段(对代码进行了一些小的改进)
* {
list-style: none;
margin: 0;
padding: 0;
box-sizing: border-box;
}
*::before,
*::after {
box-sizing: border-box;
}
a {
text-decoration: none;
}
html,
body {
width: 100%;
height: 100%;
}
.container {
display: grid;
grid-template-columns: 280px 1fr;
height: 100%;
}
.leftbar {
background: #1D2126;
height: 100%;
}
.rightbar {
display: grid;
grid-template-rows: 100px 1fr;
}
.header {
display: grid;
grid-template-rows: 30px 70px;
}
.topnav {
background: #1A1E23;
}
.mainnav {
background: #1D2126;
}
.content {
background: #21252B;
overflow-y: scroll;
}
.logo img {
width: 80%
}
<body>
<div class="container">
<div class="leftbar">
<div class="logo">
<img src="https://www.csgoroll.com/en/assets/logo.png" />
</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>