我想使用提交按钮图像而不是标准按钮.我在Google和SO上搜索并获得了一些不同的方法.
使用图像作为提交按钮的正确方法是什么?
此外,我想为按钮添加三种状态 - 正常,悬停,onclick
我尝试了什么
HTML
<input type="submit" value="Subscribe">
Run Code Online (Sandbox Code Playgroud)
CSS
input[type=submit] {
background:url(../images/btn-subscribe.gif) none;
text-indent:-9999px;
width:109px;
height:41px;
}
Run Code Online (Sandbox Code Playgroud)
出现了什么
它应该显示什么
Ahs*_*hid 28
编辑:
我想你正试图在这个DEMO中做到这一点
按钮有三种状态:正常,悬停和活动
您需要使用CSS Image Sprites作为按钮状态.
/*CSS*/
.imgClass {
background-image: url(http://inspectelement.com/wp-content/themes/inspectelementv2/style/images/button.png);
background-position: 0px 0px;
background-repeat: no-repeat;
width: 186px;
height: 53px;
border: 0px;
background-color: none;
cursor: pointer;
outline: 0;
}
.imgClass:hover{
background-position: 0px -52px;
}
.imgClass:active{
background-position: 0px -104px;
}
Run Code Online (Sandbox Code Playgroud)
<!-- HTML -->
<input type="submit" value="" class="imgClass" />
Run Code Online (Sandbox Code Playgroud)
asp*_*rin 11
<input type="image" src="path to image" name="submit" />
Run Code Online (Sandbox Code Playgroud)
更新:
对于按钮状态,您可以使用type ="submit"然后为其添加一个类
<input type="submit" name="submit" class="states" />
Run Code Online (Sandbox Code Playgroud)
然后在css中,使用背景图像:
.states{
background-image:url(path to url);
height:...;
width:...;
}
.states:hover{
background-position:...;
}
.states:active{
background-position:...;
}
Run Code Online (Sandbox Code Playgroud)
小智 8
<INPUT TYPE="image" SRC="images/submit.gif" HEIGHT="30" WIDTH="173" BORDER="0" ALT="Submit Form">
标准提交按钮的位置TYPE="submit"
,我们现在有TYPE="image"
.图像类型默认为表单提交按钮.更简单