简体   繁体   English

当背景图片网址更改时,按钮大小也会更改

[英]The button size change when background image url change

Currently I have a button 目前我有一个按钮

<input id="fireAction" type="button" class="submit" onclick="disableSubmit('preFlight');"><br>

Then I change the background image of the button in different case 然后我在不同情况下更改按钮的背景图像

eg. 例如。

#('#fireAction').css('background-image','url(fail.jpg)');
#('#fireAction').css('background-image','url(success.jpg)');

However, since the size of fail.jpg / success.jpg is not the same, how to define some css (Tried width:auto but not working) to make the button fit the size according to the size of background image? 但是,由于fail.jpg / success.jpg的大小不同,如何根据背景图像的大小定义一些CSS(尝试宽度:自动但不起作用)以使按钮适合大小? thanks 谢谢

I don't know whether you are looking for JS, jQuery or CSS answer, but as far as CSS goes, you cannot resize the element based on the background-image , what you can do is, you can use input type=image here 我不知道您是否在寻找JS,jQuery或CSS答案,但是就CSS而言,您无法基于background-image调整元素的大小,可以做的是,您可以在此处使用input type=image

<input type="image" src="#" alt="Image" />

Or if you want to stick with JavaScript or jQuery, than declare 2 classes with custom width's and toggle them as per your requirement 或者,如果您要使用JavaScript或jQuery,则可以声明2个具有自定义宽度的类,然后根据需要进行切换

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

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