你甚至不需要按钮。您只能拥有输入字段并使用不透明度隐藏它,并且使用:after
您可以设置按钮样式。请注意,:after
不兼容 IE7 及更早版本:
HTML
<form>
<input type="file">
</form>
CSS
input[type="file"] {
margin:19px;
position:absolute;
left:0;
top:0;
z-index:2;
font-size:31px;
clip:rect(0px, 123px, 40px, 0px);
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
filter:alpha(opacity=0);
-moz-opacity:0;
-khtml-opacity:0;
opacity:0;
}
form:after {
content:'upload file';
font:small-caps 15px Georgia;
letter-spacing:1px;
border-radius:10px;
border:1px solid #eee;
width:100px;
padding:10px;
margin:20px;
text-align:center;
position:absolute;
left:0;
top:0;
z-index:1;
background-color:#f8f8f8;
}
form {
color:#666;
}
form:hover:after {
background-color:#f3f3f3!important;
color:#c00;
}
jQuery
$('input[type=file]').on('change', function () {
$(form).submit();
});
这是演示:http: //jsfiddle.net/kcKqX/