gpt4 book ai didi

html - 图像缩放以适合 Bootstrap 网格

转载 作者:太空宇宙 更新时间:2023-11-04 12:17:17 25 4
gpt4 key购买 nike

我有一个 Bootstrap 网格和里面的图像。我的图片大小不一样,所以我得到了一个难看的网格。我希望所有图像看起来大小相同。我希望它们被缩放并隐藏图像的覆盖部分。

我正在尝试使用这段代码,但没有成功:

<div class='col-xs-6 col-sm-6 col-md-3 col-lg-2'>
<a class="thumbnail fancybox" rel="ligthbox" href="url">
<img class="img-responsive" style='-ms-object-fit: cover; -moz-object-fit: cover; -o-object-fit: cover; -webkit-object-fit: cover; object-fit: cover; overflow: hidden; -ms-transition: 1s all; -moz-transition: 1s all; -o-transition: 1s all; -webkit-transition: 1s all; transition: 1s all;' alt="" src="url">
</a>
</div> <!-- col-6 / end -->

我知道把样式放在那里并不干净,但只是为了测试。

最佳答案

我想这就是您要找的。

JS:

function squareThumbs() {
var thumbs = document.getElementsByTagName("img");

for (i = 0; i < thumbs.length; i++) {
if (thumbs[i].parentNode.className.indexOf("thumbnail") != -1){
thumbs[i].style.height = thumbs[i].clientWidth + "px";
console.log(thumbs[i].clientWidth);
console.log(thumbs[i].clientHeight);
}
console.log(thumbs[i].parentNode.className);
}
}
squareThumbs();
window.onresize = squareThumbs;

HTML:

<div class="col-xs-6 col-sm-6 col-md-3 col-lg-2">
<a class="thumbnail fancybox" rel="ligthbox" href="#" style="overflow:hidden;">
<img src="http://placehold.it/100x125" class="img-responsive" style="width:100%;-ms-object-fit: cover; -moz-object-fit: cover; -o-object-fit: cover; -webkit-object-fit: cover; object-fit: cover; overflow: hidden; -ms-transition: 1s all; -moz-transition: 1s all; -o-transition: 1s all; -webkit-transition: 1s all; transition: 1s all;" alt="">
</a>
</div>

现场演示:http://www.bootply.com/bg1A4I9IJ0

关于html - 图像缩放以适合 Bootstrap 网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28606992/

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