【发布时间】:2021-06-09 15:48:59
【问题描述】:
我有一个主要的父 div。其中有两个div,左和右。我能够使左右 div 独立滚动。但是,在右侧 div 中,又有两个 div(1 和 2)。我正在尝试使 1 和 2 独立滚动。滚动发生在主父级的整个右 div 内。我不确定出了什么问题以及为什么 2 占据了正确 div 的整个高度,而它应该只占据其内容的高度。在这里,1 比 2 长,即使 2 停止也应该滚动。我已经为下面的所有 div 附加了 css。
主 div 是所有 div 的父级
.main{
display: flex;
font-family: 'Rubik', sans-serif;
font-size: 20px;
width: 100vw;
height: 100%;
background: #f7f7f7;
}
在主 div 中,我有左右 div,它们独立滚动
.left{
flex-grow: 1;
height: 90vh;
position: static;
top: 0;
overflow-y: auto;
overflow-x: hidden;
}
.right{
flex-grow: 1;
height: 90vh;
position: static;
top: 0;
overflow-y: auto;
overflow-x: hidden;
}
在右侧的 div 中,我有第一个和第二个不是独立滚动的。第一个比第二个长。 Second 应该在其内容结束时停止滚动,但它的高度是 first。我不确定为什么。当第二个停止时,我试图让第一个继续滚动。
.first{
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 900px;
flex: 1 1;
}
.second{
width: 467px;
background-color: #2b2f3e;
flex: none;
}
谁能帮我弄清楚这有什么问题?谢谢
.main {
display: flex;
font-family: 'Rubik', sans-serif;
font-size: 20px;
width: 100vw;
height: 100%;
background: #f7f7f7;
}
.left {
flex-grow: 1;
height: 90vh;
position: static;
top: 0;
overflow-y: auto;
overflow-x: hidden;
background-color: blue;
}
.right {
flex-grow: 1;
height: 90vh;
position: static;
top: 0;
overflow-y: auto;
overflow-x: hidden;
}
.first {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 900px;
flex: 1 1;
background-color: yellow;
}
.second {
width: 467px;
background-color: #2b2f3e;
flex: none;
}
<div class="main">
<div class="left">
<h1>Left</h1>
<p>Data</p>
</div>
<div class="right">
<h1>Right</h1>
<div class="first">
<h2>First</h2>
<p>Data</p>
</div>
<div class="second">
<h2>Second</h2>
<p>Data</p>
</div>
</div>
</div>
【问题讨论】:
-
.1和.2是 W3C specifications 所描述的 CSS 类的无效选择器。但是,如果您仍然想使用它们,您可以写[class="1"]和[class="2"] -
@Reyno 是的,我只是写了它,以更简单的方式解释问题
-
请点击edit,然后点击
[<>]sn-p 编辑器并创建minimal reproducible example -
如果你去lipsum.com拿一些数据来展示当然更好
标签: javascript html css reactjs