【发布时间】:2014-05-09 12:27:08
【问题描述】:
我现在在一个网站项目中使用 Bootstrap 3。 我在使用 img-responsive 使我的图像具有响应性时遇到问题。
我想要的是在一个容器中并排放置 4 张图像,它们的高度和比例都相同,随着屏幕尺寸的变化。
按照 Bootstrap 网格系统,我的图像总共占据了 12 列。
1 = 最左边的图像 2 = 第二个图像 3 = 从左数第三个图像 4 = 最右边的图像
1 - 3 列,960x640 2 = 2 列,640x640 3 = 4 列,1280x640 4 = 3 列,960x640
HTML:
<div class="container">
<div class="row">
<div class="col-md-3">
<img class="responsive" src="/image/1.jpg" />
</div>
<div class="col-md-2">
<img class="responsive" src="/image/2.jpg" />
</div>
<div class="col-md-4">
<img class="responsive" src="/image/3.jpg" />
</div>
<div class="col-md-3">
<img class="responsive" src="/image/4.jpg" />
</div>
</div>
如何确保它们在缩放时都具有相同的高度?现在所有的图片都简单地将 img-responsive 作为一个类,使其最大宽度为 100%,高度设置为自动,并显示为块。
CSS:
.img-responsive {
display: block;
max-width: 100%;
height: auto;
}
【问题讨论】:
-
你能提到原始图像尺寸吗?也许不同的列大小与相同高度的图像宽度不成比例。最好的方法是为图像提供成比例的宽度和高度:自动
-
@Sagi_Avinash_Varma 是的,我刚刚添加了这些!我认为这实际上可能是问题所在......
-
这个网站真的很有帮助。 helloerik.com/…
-
如果您不关心 IEgithub.com/twbs/bootstrap/pull/13203
标签: css image twitter-bootstrap twitter-bootstrap-3