首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在div中使用包含环绕的flex列,占用所有剩余空间。

在div中使用包含环绕的flex列,占用所有剩余空间。
EN

Stack Overflow用户
提问于 2021-01-29 13:38:52
回答 1查看 123关注 0票数 1

我用的是顺风,但我的问题更多的是关于柔板箱。我有这4个‘节点’,我想要包装在列,但它们没有包装时,宽度结束。我不希望这一页超过这一页的高度。以下是我目前的尝试:

代码语言:javascript
复制
<link href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.0.2/tailwind.min.css" rel="stylesheet"/>
<div class="flex flex-col bg-blue-100 h-screen">
  <h1 class="text-center text-3xl bg-blue-200 py-2">My Header</h1>
  
  <div class="flex-auto flex flex-col flex-wrap">
    <div class="bg-blue-300 border-2 border-black h-16 w-12"></div>
    <div class="bg-blue-300 border-2 border-black h-16 w-12"></div>
    <div class="bg-blue-300 border-2 border-black h-16 w-12"></div>
    <div class="bg-blue-300 border-2 border-black h-16 w-12"></div>
  </div>
</div>

我的预期目标是布局看起来类似于这样:

我知道这个问题可能与此有关,因为浏览器不知道何时开始包装,但我仍然没有找到对我来说有意义的解决方案。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-29 13:51:23

首先,我尝试增加一个固定高度的弹性父母,这似乎是可行的,但不是一个非常优雅的解决方案。因此,我决定这样做:)添加溢出参数似乎可以做到这一点。

代码语言:javascript
复制
<link href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.0.2/tailwind.min.css" rel="stylesheet"/>
<div class="flex flex-col bg-blue-100 h-screen">
  <h1 class="text-center text-3xl bg-blue-200 py-2">My Header</h1>
  
  <div class="flex-auto flex flex-col flex-wrap overflow-auto">
    <div class="bg-blue-300 border-2 border-black h-16 w-12"></div>
    <div class="bg-blue-300 border-2 border-black h-16 w-12"></div>
    <div class="bg-blue-300 border-2 border-black h-16 w-12"></div>
    <div class="bg-blue-300 border-2 border-black h-16 w-12"></div>
  </div>
</div>

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65955564

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档