简体   繁体   English

带有纯HTML / CSS图像的按钮

[英]Buttons with images in plain HTML / CSS

除了文本,是否可以将图像添加到常规<input type = "button" />

Yes - you should be able to set the background image on the button in CSS. 是的-您应该能够在CSS中的按钮上设置背景图片。 My preferred method is to use the button tag eg 我的首选方法是使用按钮标签,例如

<button type="submit">text</button>

You can put any html you want within the tag and style it. 您可以将所需的任何html放在标记中并设置其样式。

您需要“图像”输入类型

<input type="image" src="/path/to/image.png" value="Click here" size="32,32" border="0" />

We can have css for button . 我们可以为按钮添加CSS。

background: url(images/blue.png)  ;

Button in HTML (For location I'd normally place all images in a images folder) HTML中的按钮(有关位置,我通常将所有图像放置在图像文件夹中)

<BUTTON type="submit" src="/images/Button.png" value=""> 

Button via CSS , where myBtn is defined in the class file 通过CSS进行按钮,其中myBtn在类文件中定义

<BUTTON type="submit" class="myBtn" value=""> 

Where myBtn is defined in the class file 类文件中定义了myBtn的位置

.myBtn{ 
background: url(/images/Button.PNG) no-repeat; 
cursor: pointer; 
width: 140px; 
height: 80px; 
border: none; 
} 
<input type="button" style="background-image:url(flower.jpg)" value="Click">

它将使用HTML设置按钮的背景图像。

An image in the button or an image as the button? 按钮中的图像还是按钮中的图像?

Image AS button: 图像AS按钮:

<input type="image" src="/images/myImage.png" alt="An image as a button"/>

Image inside button....I don't think so. 按钮内的图片...。我不这么认为。

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

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