[英]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.