简体   繁体   English

如何在 ngx-bootstrap 轮播中限制高度而不过度拉伸大屏幕上的宽度

[英]How to limit height in a ngx-bootstrap carousel without overly stretching the width on large screens

I have this stackblitz below with an ngx-bootstrap carousel.我在下面有一个带有 ngx-bootstrap 轮播的 stackblitz。

https://stackblitz.com/edit/ngx-bootstrap-tuizsh?file=app%2Fapp.component.html https://stackblitz.com/edit/ngx-bootstrap-tuizsh?file=app%2Fapp.component.html

I've set the max-height for each img tag to 600px (don't want the height larger than this on large screens)我已将每个 img 标签的最大高度设置为 600 像素(不希望在大屏幕上大于此高度)

It looks fine on mobile and even on ipad/ipad pro in vertical mode.它在移动设备上甚至在垂直模式下的 ipad/ipad pro 上看起来都很好。 But as soon as I expand an ipad to horizontal or view it on a larger monitor in full screen the image starts to stretch its width too much and doesn't look good.但是,一旦我将 ipad 扩展到水平或在更大的显示器上全屏查看它,图像就会开始过度拉伸其宽度并且看起来不太好。

Is there any way to fix the width from stretching like this while keeping the max-height at 600px?有什么方法可以在将最大高度保持在 600px 的同时固定宽度这样的拉伸?

I've gone seen the carousel and after changing the window width the image moves to the left leaving a white space on the left.我已经看到了旋转木马,在更改了 window 宽度后,图像向左移动,在左侧留下一个空白区域。 I added a min-width of 100% and an object fit of cover to prevent it from being squeezed up to the center but otherwise spread.我添加了一个 100% 的最小宽度和一个 object 盖板,以防止它被挤压到中心但否则会扩散。

img {
  max-height: 600px !important;
  min-width: 100%;
  max-width: 100%;
  object-fit: cover;
  object-position: center; // You can change this to bottom, right or left depending 
   // on the position you want.
}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM