【发布时间】:2022-01-31 21:13:57
【问题描述】:
我有一个具有这种样式的 flex 容器:
section {
width: 100vw;
height: 100vh;
display: flex;
overflow-y: scroll;
justify-content: center;
align-items: center;
flex-direction: column;
}
这部分有一些孩子(比如两个带有#one 和#two id 的div)。当我将它们的高度设置为height: 100%; 时,我希望它们使部分滚动(因为 2*100% = 200%,对吗?)。但相反,它们只是溢出了该部分。我如何做到这一点?
更具体地说,在以下 HTML 中:
<body>
<div id="root">
<section>
<div id="one">Hi im div 1!</div>
<div id="two">Hi im div 2!</div>
</section>
<section>
<div id="three">Hi im div 3!</div>
</section>
</div>
</body>
以及正文和div#root的以下css:
body{
width: 100vw;
height: 100vh;
overflow-x: hidden;
overflow-y: scroll;
scroll-behavior: smooth;
}
#root{
width: 100%;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
#one, #two{
height : 100%;
}
我希望第一部分是可滚动的,而第二部分是完全适合视口的。很明显div#root 也可以滚动。
【问题讨论】:
-
添加相关的 HTML。
-
你可以使用自动溢出
-
@Saout 在哪个元素上?
-
该部分,但滚动已经在您的示例上工作,但是当不需要滚动时,您不能,尝试将高度设置为更小以了解发生了什么
-
@Sarout 对不起,我不明白:D,你能展示一个代码示例吗?