javascript - 按钮的背景图像不会缩小

标签 javascript css button background-image

我尝试缩小按钮的背景图像,如 How to make background image shrink proportionally to fit button size in javascript? .

但它不起作用:

enter image description here

<button id="inc-fps-btn"
        class="ui button"
        style="height:20px;
               width:20px;
               background-size: 100%;
               background-size: 20px auto;">
    <img src="res/img/inc-btn-30.png">
</button>

其中 inc-btn-30.png 是一张 30 * 30 图片。

我看不出哪里出了问题。

最佳答案

这是您要找的吗?

试试这些方法中的任何一个

<div>
  <strong>1. Make the image as button background. </strong>
</div>
<div>
  <button id="inc-fps-btn" class="ui button" style="height:40px; width:40px; background: url('https://placeimg.com/131/131/nature');  
        background-size: cover; ">
</button>
</div>

<div>
  <strong>2. Make the image in button with full size. </strong>
</div>
<div>
  <button id="inc-fps-btn" class="ui button" style="height:40px;
               width:40px; padding: 0;
               background-size: 100%;
               background-size: 20px auto;">
    <img src="https://placeimg.com/131/131/nature" style="width: 100%; height: auto">
</button>
</div>

关于javascript - 按钮的背景图像不会缩小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51463612/

相关文章:

javascript - 如何为按钮添加第二次关闭功能?

javascript - 如何使用 firefox addon sdk 将脚本即 gmail.js api directlty 注入(inject) gmail 内容?

javascript - 应用程序加载后的 ng-include

javascript - 在Google应用程序脚本GUI中显示Gmail消息

javascript - 在更改功能之外获得正确的选择

javascript - jQuery 可排序自己的元素作为占位符

html - 添加 xs 值后大屏幕上的 Bootstrap 列困惑

html - 表行 : only bottom border is styled 中的顶部和底部边框

javascript - jQuery 使用 on 方法将函数绑定(bind)到按钮

xcode - NSButton 多次点击