html - 使所有图像在 Bootstrap 中显示相同的高度

标签 html css twitter-bootstrap

我试图让所有一行 4 张图像都具有相同的高度大小,我已经尝试使用 css 调整宽度和高度但似乎没有任何效果,肖像图像总是比风景图像高那些,这是代码:

<div class="container" >
    <div class="jumbotron" style="background: rgba(200, 54, 54, 0.0);">
        <div class="row">
            <div class="col-lg-3 col-md-6 col-sm-12 col-xs-12">
                <a href="#"><img class="left-block img-responsive" src="images/genimage.png" width="160" height="160" alt="" /></a>
                <p style="width: 200px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; ">One Random Item</p>
                <p>50 €</p>
            </div>
            <div class="col-lg-3 col-md-6 col-sm-12 col-xs-12">
                <a href="#"><img class="left-block img-responsive" src="images/genimage.png" width="160" height="160" alt="" /></a>
                <p style="width: 200px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; ">Another Random Item</p>
                <p>50 €</p>
            </div>
            <div class="col-lg-3 col-md-6 col-sm-12 col-xs-12">
                <a href="#"><img class="left-block img-responsive" src="images/genimage2.jpg" height="160" width="160" alt="" /></a>
                <p style="width: 200px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; ">Another another Random Item</p>
                <p>50 €</p>
            </div>
            <div class="col-lg-3 col-md-6 col-sm-12 col-xs-12">
                <a href="#"><img class="left-block img-responsive" src="images/genimage.png" width="160" height="160" alt="" /></a>
                <p style="width: 200px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; ">Any other Random Item Any other Random Item </p>
                <p>50 €</p>
            </div>
        </div>

是这样的:

enter image description here

这就是我想要的(都是一样的高度)

enter image description here

最佳答案

您可以去掉 HTML 中的宽度/高度属性并使用 CSS 来实现。只需明确设置您的高度,并将宽度设置为 auto。例如:

.img-responsive {
    width: auto;
    height: 100px;
}

您需要注意在水平方向上留出足够的空间,因为一旦缩放这些图像,您将不知道它们的确切宽度。

关于html - 使所有图像在 Bootstrap 中显示相同的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34425898/

相关文章:

css - 使用 CSS 在图像上添加 3D 效果

javascript - jQuery 菜单不会在 Safari 中折叠

javascript - HTML 和 CSS 垂直组织 div

html - Twitter Bootstrap 如何在内部工作

html - 在 dataTable 列中创建一个异步事件并根据响应呈现一个按钮

html - XSLT 不允许我使用自动关闭的 img 和 br 标签

php - 隐藏 URL 的 index.php(或 index.html)

html - 在页面中将标签和输入居中

css - 如何覆盖边框 :none?

javascript - 下拉菜单内的下拉菜单