html 使图像按钮尺寸等于图像尺寸

html make image button dimensions equal to image dimensions

我正在使用一个 input type = 'image' 元素作为一个图标,它切换到 pause/start 一个自动收报机。然而,当我使用图标时,图像比按钮本身小得多(没有为按钮设置任何尺寸)。有没有一种方法可以使按钮的尺寸等于其 src 属性中的图像,而无需对图像本身的宽度和高度进行硬编码?我看到的示例只是使用硬编码的宽度和高度。顺便设置硬编码宽度和高度不起作用。

正在设置图像类型的输入。即

<input type="image" src="http://placehold.it/20x20" />

尺寸将默认为图像的尺寸。这是 jsbin to demo。您可能还有其他 css 影响按钮