【发布时间】:2020-03-06 21:59:09
【问题描述】:
我正在尝试创建一个包含一些图像的响应式轮播。
有两种图像:
1. 较小的图像
2. 大图。
我希望较小的图像(无论多小)进行拉伸和填充,以及调整大图像的大小,或者如果无法做到这一点,则将其裁剪并按原样调整大小的图像进行填充。
此外,如您所见,我设置了max-height:500px,这对于响应式响应来说不是一个好习惯,但如果我不这样做,大图像会显得比我想要的更大。
因此,基本上,我正在寻找某种方法来调整图像的大小并使其适合我的轮播,而不管图像的尺寸如何。现在,我可以裁剪较大的图像,但无法拉伸和填充较小的图像。答案对我不起作用。
<div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
<div class="carousel-inner" role="listbox"
style="width:100% !important; height:100% !important; max-height:500px !important;">
<div class="carousel-item active"
style="background-size: cover !important; background-position: 50% 50% !important; min-width: 100% !important; min-height: 100% !important;">
<img class="d-block w-100 h-100"
src="{{ v.url }}">
</div>
</div>
<a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
我已经尝试了该问题的几乎所有答案,例如background-size: cover 等等,但没有一个对我有用。因此,请在将其标记为重复之前或在参考其他答案之前测试一次。
我不认为它是否需要,但这个轮播在网格的列中。
如果你不使用js 也能做到这一点,那就太好了,因为我不是前端开发人员,我只想修复它而不浪费太多时间。
【问题讨论】:
-
您尝试过图像上的
object-fit: cover;属性吗? -
是的,先生,我做到了。
-
在该项目上带有特定的
height和width,例如object-fit: cover; height: 60vh; width: 100%;?
标签: html css bootstrap-4 carousel