简体   繁体   English

Bootstrap 3-一些图像调整大小,另一些则没有

[英]Bootstrap 3 - some images resize, other don't

I'm using Bootstrap 3 and, as you see in the code, i have two images. 我正在使用Bootstrap 3,正如您在代码中看到的那样,我有两个图像。 Both of them have the ".img-responsive" class so i don't know why only the first one is resizing and the second one is always the same size. 他们两个都有“ .img-响应”类,所以我不知道为什么只有第一个调整大小,而第二个总是相同大小。

HTML : HTML:

<div class="container-fluid">
    <img src="img/ea.png" class="img-responsive" id="img-center" width="700" height="229">
</div>

<div class="container-fluid">
    <div class="row">
        <div class="col-lg-12 frase">
            <p>LOREM IPSUM</p>
        </div>
    </div>
</div>

<div class="container-fluid">
    <a href="#">
        <img src="img/arrow.PNG" class="img-responsive" style="margin:0 auto;" width="80px" height="65px">
    </a>
</div>

In case you're wondering, the id "img-center" only has "margin:0 auto" and "margin-bottom:45vh; 如果您想知道,ID“ img-center”仅具有“ margin:0 auto”和“ margin-bottom:45vh”;

When you apply the width and height attributes to an element, it will override the width: 100% setting of .img-responsive . 当您将widthheight属性应用于元素时,它将覆盖.img-responsivewidth: 100%设置。

However, the reason that the first image is responsive and the second is not, you did not append px to the end of the sizes for the first image. 但是,第一个图像响应而第二个图像没有响应的原因是,您没有在第一个图像的尺寸末尾附加px The browser would not know how to interpret that, so it would revert to the original width: 100%; 浏览器不知道该如何解释,因此它将恢复为原始width: 100%; setting. 设置。

<img ... class="img-responsive" ... width="700" height="229">
<img ... class="img-responsive" ... width="80px" height="65px">

To make both images responsive, you have to remove the fixed sizing attributes. 要使两个图像都具有响应性,您必须删除固定的大小调整属性。

<img src="img/ea.png" class="img-responsive" id="img-center">
<img src="img/arrow.PNG" class="img-responsive" style="margin:0 auto;">

That because you're using different inline-style width and height in the both of them, so try to remove the inline style because is prevent the class img-responsive to be applicable. 那是因为您在两者中都使用了不同的内联样式widthheight ,所以请尝试删除内联样式,因为这会阻止img-responsive类适用。

First img : 第一张img:

<img src="http://img.freepik.com/free-photo/background-with-white-squares-free-vector_23
-2147501484.jpg?size=338c&ext=jpg" class="img-responsive" id="img-center">

Second img : 第二张img:

<img src="http://img.freepik.com/free-photo/background-with-white-squares-free-vector_23
-2147501484.jpg?size=338c&ext=jpg" class="img-responsive" style="margin:0 auto;" >

Hope this help. 希望对您有所帮助。 Take a look at Working Fiddle . 看看工作小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM