简体   繁体   English

如何使此垂直列表填充容器的垂直高度?

[英]How can I make this vertical list fill the vertical height of the container?

I am using flexbox to create my 2 column layout. 我正在使用flexbox创建2列布局。 Everything is working well, however I'd like to have my list items in my right column always take up the full height. 一切工作正常,但是我希望我的右栏中的列表项始终占满整个高度。 Each <li> element contains an <img> element. 每个<li>元素都包含一个<img>元素。

When I start to shrink the window width, as you can see, the <ul> element's height starts to scale up to keep it's aspect. 如您所见,当我开始缩小窗口宽度时, <ul>元素的高度开始扩大以保持其外观。

If I make the window really wide, the list element(s) will start to get clipped off. 如果我将窗口确实变宽,则列表元素将开始被剪切掉。

I'd like to always be able to see all 4 list items. 我希望始终能够看到所有4个列表项。 I'd be OK if I have to lock the width(s) or height(s) down. 如果我必须将宽度或高度锁定下来,我会没事的。 As you can see, I've set a min/max height but no luck. 如您所见,我设置了最小/最大高度,但是没有运气。 I am also OK with using the <li> elements as a container/viewable area for the images. 我也可以使用<li>元素作为图像的容器/可视区域。 Meaning, if the image inside the <li> gets clipped off overflow:hidden or something - that's fine. 意思是,如果<li>的图像被裁剪掉,可能是overflow:hidden或其他东西-很好。 I am just trying to keep the two columns 50% each, and the right column always take the full height. 我只是试图将两列保持为50%,而右列始终占据整个高度。

HTML 的HTML

<div id="container">
    <div id="foo">
       ...
    </div>
    <div id="bar">
        <ul>
            <li><img></li>
            <li><img></li>
        </ul>
    </div>
</div>

CSS 的CSS

#container {
    display: flex;
    flex-direction: row;
    height: 600px;
    min-height: 600px;
    max-height: 600px;
}

#foo {
  display: flex;
  flex-direction: column;
  order: 1;
  width: 50%;
}

#bar {
    display: flex;
    flex-direction: column;
    order: 2;
    width: 50%;
}

在此处输入图片说明

Only give display: flex to the parent container. display: flex到父容器。 All children the inside parent container will be equal to the height of the child with the maximum height. 父容器内部的所有子代将等于最大高度的子代的高度。

.container {
  display: flex;
}

.foo {
  width: 50%;
  order: 1;
}

.bar {
  width: 50%;
  order: 2;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何让 CSS Grid Container 始终填充可用的垂直空间 - How to make CSS Grid Container Always Fill Available Vertical Space 如何在不添加空格的情况下使垂直文本填充整个页面高度 - how do i make vertical text fill full page height without adding space 如何使图像以设定的高度填充整个容器 - How can I make the image fill the whole container with a set height 如果输入文本标签高度大于文本高度,如何使光标垂直对齐到中间? - How can I make cursor vertical alignment to middle if the input text tag height is more than the text height? 如何从导航栏创建一个选项卡以使用 bootstrap5 填充所有垂直空间? - How can I make a tab from a navbar to fill all the vertical space with bootstrap5? 如何将垂直列表居中? - How can I center a vertical list? 如何在 Materialise CSS 中使卡片的垂直高度不同? - How do I make vertical height of cards vary in Materialize CSS? 如何在没有垂直滚动标题的情况下使DIV的浏览器高度为100% - How can I make DIV 100% height of browser without vertical scrolling of header 如何使所有类别的垂直子菜单容器位置相同 - how can i make vertical submenu container position same for all categories 在不使用浮动的情况下使图像填充剩余的垂直高度 - Make image fill remaining vertical height without using float
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM