我想创建一个应用程序布局,其中包含一个顶部带有div的工具栏
然后是带有顶部导航栏的侧边栏和内容窗口
我的结构几乎可以使用了,但是我无法滚动到内容容器的底部。我希望其他所有问题都得到解决。我已经包含了代码和小提琴。我觉得这与放置在内容容器上的h屏幕有关,但是如果尝试使用h-full,则根本无法滚动。
<div class="h-screen overflow-hidden" >
<div class="p-4 bg-yellow-500">
<div class="h-10 bg-green-500">
</div>
<div class="h-10 bg-blue-500">
</div>
</div>
<div class="flex">
<div class="w-48">
sidebar
</div>
<div class="w-full bg-indigo-500 p-2 ">
<div class="h-10 bg-orange-500 w-full">
topnav
</div>
<div class=" flex-1 relative z-0 overflow-y-auto bg-green-500 h-screen">
content
<div class="h-10 bg-white m-3"></div>
<div class="h-10 bg-white m-3"></div>
<div class="h-10 bg-white m-3"></div>
<div class="h-10 bg-white m-3"></div>
<div class="h-10 bg-white m-3"></div>
<div class="h-10 bg-white m-3"></div>
<div class="h-10 bg-white m-3"></div>
<div class="h-10 bg-white m-3"></div>
<div class="h-10 bg-white m-3"></div>
<div class="h-10 bg-white m-3"></div>
<div class="h-10 bg-white m-3"></div>
<div class="h-10 bg-white m-3"></div>
<div class="h-10 bg-white m-3"></div>
<div class="h-10 bg-white m-3"></div>
<div class="h-10 bg-white m-3"></div>
<div class="h-10 bg-white m-3"></div>
<div class="h-10 bg-white m-3"></div>
<div class="h-10 bg-white m-3"></div>
<div class="h-10 bg-white m-3">Last One</div>
</div>
</div>
</div>
</div>
答案 0 :(得分:1)
您正在使用flexbox最小尺寸算法,这会导致布局溢出。有关详细说明,请参阅此帖子:
overflow
函数也使您受阻,该函数需要固定的长度,因此实际上可能会溢出某些内容。看到这篇文章:
考虑到这些因素,您只需将其添加到代码中即可:
.main-container {
display: flex;
flex-direction: column;
/* overflow: hidden is not necessary */
}
.secondary-container {
overflow: auto;
}
.tertiary-container {
display: flex;
flex-direction: column;
}