gpt4 book ai didi

twitter-bootstrap - 如何在 Bootstrap - Carousel 中使图像缩放到全高?

转载 作者:行者123 更新时间:2023-12-03 07:08:54 33 4
gpt4 key购买 nike

我试图在 Bootstrap Carousel 控件中显示一个应该填满整个屏幕的图像。我使用的是 1024px*795px 的图像

我正在使用 Bootstrap 网站上给出的带有全尺寸图像的示例。水平方向上,它很好地填满了屏幕。但垂直方向上它的扩展性不佳。我应该添加/删除哪些属性,以便图像填满整个屏幕,尽管它们的像素尺寸较小?

我怎样才能在响应式设计中做到这一点,以便图像可以缩放任意尺寸?

我使用示例网站上的 CSS,仅更改 carousel.html 中的 CSS。

最佳答案

2019 年 Bootstrap 4.x 更新答案

由于现代浏览器现在支持object-fit,因此有better options as explained here .

Bootstrap 3.x 的原始答案

我意识到这个答案有点晚了,但我在 Bootstrap 轮播中也面临着类似的挑战。为了使 100% 高度发挥作用,轮播及其任何父容器也必须为 100% 高度。

我向 Bootstrap CSS 类添加了一些覆盖:

html,body{height:100%;}
.carousel,.item,.active{height:100%;}
.carousel-inner{height:100%;}
.fill{width:100%;height:100%;background-position:center;background-size:cover;}

然后根据您的轮播添加“fill”类:

<div class="container fill">
<div id="myCarousel" class="carousel slide">
<div class="carousel-inner">
<div class="active item">
<div class="fill" style="background-image:url('//www.portalapp.com/images/greengrass.jpg');">
<div class="container">
<h1 class="pull-left pull-middle light-color"><strong><a href="#">Slide 1</a></strong></h1>

</div>
</div>
</div>
<div class="item">
<div class="fill" style="background-image:url('//placehold.it/1024x700');">
<div class="container">
<h1 class="pull-left pull-middle light-color"><strong><a href="#">Slide 2</a></strong></h1>

</div>
</div>
</div>
</div>
<div class="pull-center">
<a class="carousel-control left" href="#myCarousel" data-slide="prev">‹</a>
<a class="carousel-control right" href="#myCarousel" data-slide="next">›</a>
</div>
</div>
</div>

这是一个工作示例:http://bootply.com/59900

关于twitter-bootstrap - 如何在 Bootstrap - Carousel 中使图像缩放到全高?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14119577/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com