我正在尝试根据按钮的大小设置图像的大小。请参阅我的以下 html 代码:
<button id="image" type="button" title="Image">
<img src = "nature.jpg" width="20" height="20" />
</button>
但我不明白。 你能帮我一下吗? 提前致谢。
最佳答案
您只需删除按钮填充和边框即可使图像完全填充它。
#image {
border: 0;
padding: 0;
}
演示:http://jsfiddle.net/nfpNL/1/
您还可以将图像设置为背景:
#image {
background: url(http://lorempixel.com/100/100/nature/1) no-repeat 0 0;
height: 20px;
width: 20px;
border: 0;
padding: 0;
}
那么你根本不需要 img
标签
演示:http://jsfiddle.net/nfpNL/
关于javascript - 我正在尝试将图像大小设置为按钮的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21930567/