简体   繁体   English

图像无响应或无法调整为最大宽度值

[英]Image not responsive nor resizing to max-width value

I am toggling 2 images, a small icon (pic1_off.png) and a much larger image (pic1_on.png) in a page of text. 我在文本页面中切换了2张图像,一个小图标(pic1_off.png)和一个更大的图像(pic1_on.png)。 The 2 images toggle between each other OK, but the larger image is too big. 2张图像可以在彼此之间切换,但较大的图像太大。 I want it be 40% of page width displaying from the left and to be responsive to screen size changes. 我希望它是页面宽度的40%,从左侧开始显示,并且能够响应屏幕尺寸的变化。 The HTML is: HTML是:

<span class="infoToggler"><img class="img-swap" src="/templates/beez_20/images/e2tw/books/science_news/hearing_loss/pic1_off.png" align="left"></span> 

the JS: JS:

jQuery(".img-swap").on('click', function() {
    if (jQuery(this).attr("class") === "img-swap") {
        this.src = this.src.replace("_off","_on");
    } else {
        this.src = this.src.replace("_on","_off");
    }
    jQuery(this).toggleClass("on");
});
});

CSS: CSS:

img.img-swap {
    max-width: 40%;
    height: auto;
}

I can't work out why the larger image is not resizing nor why it is not responsive. 我无法弄清楚为什么较大的图像没有调整大小,也没有响应。 Any help would be very welcome. 任何帮助将非常欢迎。

尝试这个

img.img-swap { max-width: (Add a pixel value) width:40%; height: auto; }

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

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