Hel*_*ira 6 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>
Run Code Online (Sandbox Code Playgroud)
这是发生的事情:
这就是我想要的(所有都有相同的高度)
Jos*_*ord 12
您可以取消HTML中的宽度/高度属性,并使用CSS执行此操作.只需明确设置高度,宽度为auto.例如:
.img-responsive {
width: auto;
height: 100px;
}
Run Code Online (Sandbox Code Playgroud)
您需要小心,水平留出足够的空间,因为一旦缩放,您将不知道任何这些图像的确切宽度.
这是一种响应方式.
.img-wrapper {
position: relative;
padding-bottom: 100%;
overflow: hidden;
width: 100%;
}
.img-wrapper img {
position: absolute;
top:0;
left:0;
width:100%;
height:100%;
}
<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="#" class="img-wrapper">
<img class="left-block" src="images/genimage.png"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="#" class="img-wrapper">
<img class="left-block" src="images/genimage.png"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="#" class="img-wrapper">
<img class="left-block" src="images/genimage.png"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="#" class="img-wrapper">
<img class="left-block" src="images/genimage.png"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>
Run Code Online (Sandbox Code Playgroud)
您将需要使用img-wrapper的填充底部来使图像显示高度,如果您希望图像显示不是100%的col但是希望它们阻止,则可以移除宽度100%从包装器中添加显示块和您想要的自定义宽度,但这应该可行.