[英]Setting Images Side by Side & responsive in bootstrap
I have written a code where 4 images are kept inside div side by side in cols. 我写了一个代码,其中4个图像在cols中并排放置在div中。
Below is the code : 下面是代码:
<div class="container-fluid">
<div class="row">
<div class="col-xs-3 col-sm-3 col-md-3">
<img src="image2.jpg" alt="1" style="width:100%; height:70%;" class="img-responsive" />
</div>
<div class="col-xs-3 col-sm-3 col-md-3">
<img src="image3.jpg" alt="1" style="width:100%; height:70%;" class="img-responsive"/>
</div>
<div class="col-xs-3 col-sm-3 col-md-3">
<img src="image4.jpg" alt="1" style="width:100%; height:70%;" class="img-responsive"/>
</div>
<div class="col-xs-3 col-sm-3 col-md-3">
<img src="image5.jpg" alt="1" style="width:100%; height:70%;" class="img-responsive"/>
</div>
</div>
</div>
This looks like this in full size window : 在全尺寸窗口中看起来像这样:
enter image description here 在此处输入图片说明
Now when the window size is minimized, the images looks like this : 现在,当窗口大小最小化时,图像如下所示:
enter image description here 在此处输入图片说明
I want the image to look the way it looks in the full size even after minimizing without the image getting stretched. 我希望图像在不缩小图像的情况下最小化后也能以完整尺寸显示。
I was able to get the view of above images without it getting stretched when i removed the style: width:100%; 当我删除样式时,我能够获得上面图像的视图而不会被拉伸:width:100%; height:70%;
高度:70%; but then in full sized window the images had blank spaces between each other.
但随后在全尺寸窗口中,图像之间会留有空白。
Please help me to get this sorted. 请帮助我进行排序。
Using 使用
class="img-responsive"
will make your images responsive across devices. 将使您的图像在所有设备上都能响应。 In specific, and as per Bootstrap's documentation , it will add
具体来说,根据Bootstrap的文档 ,它将添加
max-width: 100%;
height: auto;
display: block;
to your image elements. 您的图像元素。
You will need to lose your inline styles 您将需要失去内联样式
style="width:100%; height:70%;"
as they override everything else (Protip: never use them). 因为它们会覆盖其他所有内容(提示:请勿使用它们)。
Lastly, if you don't want the blank spaces between images you'll need to force remove the padding for each column. 最后,如果您不希望图像之间留有空白,则需要强制删除每列的填充。 Example:
例:
div.col-xs-3 {
padding: 0;
}
@FredRocha hey Fred, I tried using only img-reponsive & losing the inline styles but then the images were looking like this in full screen window size: @FredRocha嗨,弗雷德,我尝试仅使用img-responsive并丢失了内联样式,但是在全屏窗口大小下,图像看起来像这样:
也许将img响应类添加到图像将解决此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.