当前位置: 首页 > 面试题库 >

一个弹性项目设置了siblings高度限制

廉宇
2023-03-14
问题内容

我有两个同级元素,每个元素都包含动态内容。

<div class="flex">
    <div class="sibling-1"></div>
    <div class="sibling-2"></div>
</div>

在某些情况下,sibling-1然后会有更多的内容sibling-2,反之亦然。我希望第二个元素sibling-2的高度始终等于第一个元素的高度sibling-1。如果的高度sibling-2更大,则其高度sibling-1将溢出flexdiv,因此可以滚动。

有什么方法可以通过Flexbox做到这一点?


问题答案:

是的,有可能。让兄弟姐妹单独设置最大高度,并设置其他人的flex-basis: 0flex-grow: 1,然后根据规范将其扩展到他们兄弟姐妹的高度。没有绝对定位。没有设置任何元素的高度。

main {

  display: flex;

}



section {

  display: flex;

  flex-direction: column;

  width: 7em;

  border: thin solid black;

  margin: 1em;

}



:not(.limiter)>div {

  flex-basis: 0px;

  flex-grow: 1;

  overflow-y: auto;

}


<main>

  <section>

    <div>I'm longer and will scroll my overflow. in flow text in flow text in flow text in flow text in flow text in flow text in flow text in flow text in flow text in flow text in flow text in flow text in flow text in flow text in flow text in flow text in flow text in flow text in flow text

      in flow text in flow text in flow text in flow text in flow text in flow text in</div>

  </section>



  <section class="limiter">

    <div>Every parent's siblings match my height. in flow text in flow text in flow text in flow text in flow text in flow text in flow text in flow text in flow text in flow text in flow text in flow text in flow text in flow text in flow text in flow text in flow text</div>

  </section>



  <section>

    <div>I'm shorter but still match the height. in flow text in flow text in flow text in flow text in flow text in flow text in flow text in flow text in flow text</div>

  </section>

</main>


 类似资料:
  • 问题内容: 我有两个同级元素,每个元素都包含动态内容。 在某些情况下,然后会有更多的内容,反之亦然。我希望第二个元素的高度始终等于第一个元素的高度。如果的高度更大,则其高度将溢出div,因此可以滚动。 有什么方法可以通过Flexbox做到这一点? 问题答案: 是的,有可能。让兄弟姐妹单独设置最大高度,并设置其他人的和,然后根据规范将其扩展到他们兄弟姐妹的高度。没有绝对定位。没有设置任何元素的高度。

  • 我如何从弹性搜索中获得所有的结果,因为结果只显示限制只有10个。我得到了一个查询,如下所示:

  • 我的回收物品在onCreateViewHolder中膨胀 我想展示这样的东西,其中一排的高度是回收站视图的一半?在空间的其余部分添加填充物?我可以通过GridLayoutManager来完成吗? 这是我的GridLayoutManager

  • 更新:如果我必须使用flexbox,我认为没有简单的解决方案。我将使用“flex shrink:0”并使用媒体查询来调整设计。无论如何,谢谢你的帮助。 我有一个水平列表(显示: flex)与多个元素。当我缩小窗口大小时,列表元素开始缩小。不幸的是,元素的宽度几乎保持不变。锂元素占据了太多的空间。我希望li-元件的大小适合内容。如果我把"flex-收缩: 0"添加到li-元素中,宽度是正确的,但是我

  • 我想创建一个新的角度项目使用顺风CSS。我当前的CLI版本是10.1.1。到目前为止我做过的事情: 使用创建新应用程序 使用角度路由=>是 使用SCSS作为样式表 在项目根目录中运行 在src文件夹中有一个styles.scss文件,请将其修改为 null 根目录中有一个Angular.json文件 搜索关键项目=>my-app=>architect=>build 将生成器更改为 添加到选项 .

  • 如果我调整窗口的大小小于最小宽度flex项目的总数(此处为653px),则会出现一个滚动条,但flexbox采用当前窗口的大小,并且flex项目没有红色背景,我想知道如何在不键入以下特定值的情况下为flexbox容器设置最小宽度: 我不希望收缩flex项目,但一个css的方式来获得: flexbox.min(flex_items_min_width) https://codepen.io/papa