[英]Set same height for all images
I have three images and I am displaying them one by one, they have different height and that push and pull other content based on image height.我有三张图像,我将它们一张一张地显示出来,它们具有不同的高度,并根据图像高度推拉其他内容。 When I set fixed height for image, the height will not be responsive anymore.当我为图像设置固定高度时,高度将不再响应。 How to set same height for these images where responsive can still work?如何为这些响应式仍然可以工作的图像设置相同的高度?
This is my Script:这是我的脚本:
var i = 0; var path = new Array();
path[0] = "/pic/Company.png";
path[1] = "/pic/S031.png";
path[2] = "/pic/AnnualReport2015_f.png";
function swapImage() {
document.slide.src = path[i];
if (i < path.length - 1) i++;
else i = 0;
setTimeout("swapImage()", 3000);
}
CSS but it does not solve my problem : CSS 但它不能解决我的问题:
#left-img
{
max-height: 500px;
}
HTML: HTML:
<div class="col-md-8">
<img name="slide" src="home1.jpg" class="img-responsive" id="left-img"/>
</div>
Use their class
instead of their id
, and btw, id
should be unique for every image使用他们的class
而不是他们的id
,顺便说一句,每个图像的id
应该是唯一的
With max-height: 300px
, only bigger gets resized down to 300px, using height: 300px
will do the same but also up size smaller (and all will keep their aspect ratio).使用max-height: 300px
,只有更大的会被调整到 300px,使用height: 300px
会做同样的事情,但也会变小(并且都将保持它们的纵横比)。
.img-responsive { height: 300px; }
<div class="col-md-8"> <img name="slide" src="http://placehold.it/150x200" class="img-responsive" id="left-img-1"/> <img name="slide" src="http://placehold.it/150x300" class="img-responsive" id="left-img-2"/> <img name="slide" src="http://placehold.it/150x400" class="img-responsive" id="left-img-3"/> <img name="slide" src="http://placehold.it/150x500" class="img-responsive" id="left-img-4"/> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.