我有这四个响应的图像。但是,有时候由于窗口的大小,图像看起来不正确。一个例子是这样的:如何在Bootstrap中保持图像大小一致?
如何使图像响应和保持图像的比例是多少?
#books_div {
position: absolute;
left: 50%;
top: 25%;
transform: translatex(-50%);
}
#books_text {
position: absolute;
left: 50%;
top: 15%;
transform: translatex(-50%);
}
#books_div img {
margin-bottom: 20px !important;
}
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet"/>
<!-- Books -->
<h2 id='books_text'> We Giveaway Free Books </h2>
<div class="row" id='books_div'>
<div class="col-lg-3 col-sm-6 portfolio-item">
<a href="#">
<img class='img-responsive' src="https://images.gr-assets.com/books/1474154022l/3.jpg" alt="" style="width:200px;height:276px;">
</a>
</div>
<div class="col-lg-3 col-sm-6 portfolio-item">
<a href="#">
<img class='img-responsive' src="https://images.gr-assets.com/books/1328767473l/10713286.jpg" alt="" style="width:200px;height:276px;">
</a>
</div>
<div class="col-lg-3 col-sm-6 portfolio-item">
<a href="#">
<img class='img-responsive' src="https://images.gr-assets.com/books/1394566113l/20454074.jpg" alt="" style="width:200px;height:276px;">
</a>
</div>
<div class="col-lg-3 col-md-6 portfolio-item">
<a href="#">
<img class='img-responsive' src="https://images.gr-assets.com/books/1460309528l/44652.jpg" alt="" style="width:200px;height:276px;">
</a>
</div>
</div>
<!-- End of Books -->
图像具有固定的宽度和高度。我不明白这是如何响应。如果你想保持固定的尺寸,只需要在那里匹配原始比例的值。 – JJJ
@JJJ Bootstrap使其响应。尝试用代码片段玩:) – user6902601