英文:
How do I make child take up rest of the space while still being scrollable
问题
使用Tailwind,我有一个标题和一个可滚动的子div
,但可滚动的div
占用的空间多于它应该的高度。我想确保可滚动的div
不超过其容器的高度。目前,页面可以滚动,标题的高度不正确。
<div class="flex h-screen flex-col">
<div class="h-48 bg-white">一些内容</div>
<div class="h-full pb-9">
<div class="h-full overflow-y-scroll bg-red-300 [其他样式]:px-4" id="content">
<div class="sticky top-0 z-50 flex items-start justify-between bg-red-300 py-4">
<div>
<h2 class="text-xl">标题</h2>
</div>
</div>
<div class="h-full">
<h1 class="text-7xl">高度太高</h1>
<!-- 更多相同的内容 -->
</div>
</div>
</div>
</div>
https://play.tailwindcss.com/7ksq08Tm2P
我尝试在顶级父元素上设置overflow-hidden
。
英文:
Using Tailwind, I have a header and a child div
that is scrollable but the scrollable div takes up more space than it should. I want to make sure that the scrollable div
doesn't exceed the height of its container. Right now, the page scrolls and the header isn't the height it should be
<div class="flex h-screen flex-col">
<div class="h-48 bg-white">some content</div>
<div class="h-full pb-9">
<div class="h-full overflow-y-scroll bg-red-300 [&>*]:px-4" id="content">
<div class="sticky top-0 z-50 flex items-start justify-between bg-red-300 py-4">
<div>
<h2 class="text-xl">header</h2>
</div>
</div>
<div class="h-full">
<h1 class="text-7xl">too much height</h1>
<h1 class="text-7xl">too much height</h1>
<h1 class="text-7xl">too much height</h1>
<h1 class="text-7xl">too much height</h1>
<h1 class="text-7xl">too much height</h1>
<h1 class="text-7xl">too much height</h1>
<h1 class="text-7xl">too much height</h1>
<h1 class="text-7xl">too much height</h1>
<h1 class="text-7xl">too much height</h1>
<h1 class="text-7xl">too much height</h1>
<h1 class="text-7xl">too much height</h1>
<h1 class="text-7xl">too much height</h1>
<h1 class="text-7xl">too much height</h1>
<h1 class="text-7xl">too much height</h1>
<h1 class="text-7xl">too much height</h1>
<h1 class="text-7xl">too much height</h1>
</div>
</div>
</div>
</div>
https://play.tailwindcss.com/7ksq08Tm2P
I tried setting overflow-hidden
on the top level parent
答案1
得分: 0
只需要将 min-h-0
类添加到 <div class="h-full pb-9">
,因为 flex 子元素通常具有 min-height: auto
,如下所示:
https://play.tailwindcss.com/BFQ0Xah5gA
英文:
You just need to add min-h-0
class to <div class="h-full pb-9">
, because the flex child normally has min-height: auto
, like this:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论