【发布时间】:2018-04-28 11:24:25
【问题描述】:
使用 flex 布局水平滚动时如何使一行中的第一列保持粘性?
.wrapper {
display: flex;
height: 100vh;
overflow-x: auto
}
.first-column {
flex: 1 0 300px;
background: gray;
}
.second-column {
flex: 0 0 auto;
padding: 20px;
overflow: auto;
}
<div class="wrapper">
<div class="first-column">
<blockquote><i>Please, make me fixed!</i></blockquote>
</div>
<div class="second-column">
hello How are u?hello How are u?hello How are u?hello How are u?hello How are u?hello How are u?hello How are u?hello How are u?hello How are u?hello How are u?hello How are u?hello How are u?hello How are u?hello How are u?hello How are u?hello How are
u?hello How are u?
</div>
</div>
这是 *ngFor(loop) 中的一行。所以可以有多个这样的行,比如一个表格结构。我希望第二个 div 在水平滚动和通常的垂直滚动时出现在第一列下方滚动
【问题讨论】:
-
为什么不固定位置?或在第二列中滚动而不是整个换行
-
既然你在我现在删除的答案的评论中写道 “当我们垂直滚动时,我们需要两列在同一行(第一列和第二列)。这不是如果我们给出 position:fixed",就会发生这种情况,看起来这个问题缺少我们能够给出正确答案的信息。基于此,我删除了我的答案。