【发布时间】:2022-01-17 23:39:28
【问题描述】:
我有一个容器div,它的内容可以垂直增长。我使用overflow-y: auto 作为容器以使我的页面看起来不错。但是当内容的高度小于容器的高度时,我需要将所有内容放在中心。所以我使用 flexbox 来做到这一点。但问题是我无法完全滚动查看内容的顶部。
这里是有问题的代码的一个简单示例:
<html lang="en">
<head>
<style>
.container {
width: 20rem;
height: 20rem;
background-color: red;
display: flex;
justify-content: center;
flex-direction: column;
align-items: center;
overflow-y: auto;
}
.child {
width: 10rem;
height: 40rem;
background-color: blue;
flex-shrink: 0;
}
.top {
width: 1rem;
height: 1rem;
background-color: green;
}
</style>
</head>
<body>
<div class="container">
<div class="child">
<div class="top"></div>
</div>
</div>
</body>
</html>
【问题讨论】:
标签: html css web flexbox frontend