如何将 jpg 或 png 图像放入 HTML 中的按钮中
我想要一个带有图像的按钮。我正在使用这个:
<input type="submit" name="submit" src="images/stack.png" />
但它不显示图像。我希望整个按钮都是图像。
I want a button with an image in it. I am using this:
<input type="submit" name="submit" src="images/stack.png" />
But it does not show the image. I want the whole button to be the image.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
应该是
“图像”而不是“提交”。它仍然是一个点击提交的按钮。
如果您的图像比显示的按钮大;假设图像为 200x200 像素;将其添加到样式表中:
或直接添加到按钮标签中:
但请注意,像这样调整图像大小可能不会产生理想的结果;例如,如果您的图像比您希望显示的图像小得多,您将看到单个像素;另一方面,如果它更大,您就会浪费用户宝贵的带宽。因此,将图片本身调整为实际大小比通过样式表重新缩放更可取!
It should be
So "image" instead of "submit". It will still be a button which submits on click.
If your image is bigger than the button which is shown; let's say the image is 200x200 pixels; add this to your stylesheet:
or directly in the button tag:
Note however that resizing the image like this might not yield ideal results; if e.g. your image is much smaller than you want it to be shown, you will see the single pixels; if on the other hand it is much bigger, you are wasting precious bandwidth of your users. So resizing the picture itself to the actual size is preferrable over rescaling via stylesheets!
您可以使用 CSS 设计按钮样式或使用图像输入。此外,您可以使用支持内联内容的
button
元素。You can style the button using CSS or use an image-input. Additionally you might use the
button
element which supports inline content.你可以使用一些像这样的内联 CSS
应该可以发挥魔力,你也可能想做一个 border:none;摆脱标准边框。
You can use some inline CSS like this
Should do the magic, also you may wanna do a border:none; to get rid of the standard borders.
使用
Use
<button>
element instead of<input type=button />
你也可以尝试这样的方法
和 CSS class
这里给出了一个例子
you can also try something like this as well
and CSS class
An example is given here
这可能对您有用,尝试一下,看看是否有效:
This may work for you, try it and see if it works:
有用。
it works.