[英]How can I make a number of images scale proportionally based on its container height?
I'm trying to figure out how to do this.我想弄清楚如何做到这一点。 I have 3 images, all in different but specific sizes that will scroll horizontally within a container (container will have overflow: hidden
. That container should take up as much space as possible between two other divs and I'm doing that with flex-grow: 1
, and the container looks good.我有 3 张图像,所有图像的大小不同但特定,它们将在容器内水平滚动(容器将overflow: hidden
。该容器应在其他两个 div 之间占用尽可能多的空间,我正在使用flex-grow: 1
做到这一点flex-grow: 1
,容器看起来不错。
However, those images, how can I make sure they resize and keep proportions based on that container height, based on viewport height?但是,那些图像,我如何确保它们根据视口高度根据容器高度调整大小并保持比例?
I know maximum size the images can be in both width and height.我知道图像的最大尺寸可以是宽度和高度。
Please have a look at my example here: https://fvsu2.csb.app/请在这里查看我的示例: https://fvsu2.csb.app/
As you can see, the images wont resize at all if the container they are within is getting a lower height than the image itself...?如您所见,如果图像所在的容器的高度低于图像本身,则图像根本不会调整大小......? It just stops, and the bottom part goes below viewport.它只是停止,底部在视口下方。
Is this even possible?这可能吗?
U want your cardImage to be height:auto width:100%, what u have now is in reverse.你希望你的 cardImage 是高度:自动宽度:100%,你现在拥有的是相反的。
you could try this:你可以试试这个:
example:例子:
.container{height: auto}
.container .images{width: 100%}
in case of overflow, set this在溢出的情况下,设置这个
.container{height: auto; overflow: hidden}
but the images will not overflow out of the container if you set the images width to width: 100% and make sure the width of the container is in px or use bootstrap to set the width of the container eg但如果将图像宽度设置为 width: 100% 并确保容器的宽度以 px 为单位或使用 bootstrap 设置容器的宽度,则图像不会溢出容器,例如
<div class="col-lg-12 col-md-12 col-sm-12"></div>
for the container, with this the images will never overflow the container对于容器,图像永远不会溢出容器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.