最近有个项目遇到到一个上传头像的模块,不过UI在设计时候将上传按钮设计特定的样式。
本来file按钮时不能用纯CSS去改变样式的,于是在各个帖子上翻阅了半天。终于解决了
Example:
<html>
<head>
<title>test</title>
</head>
<style>
a{
display:inline-block;
width:100px;
height:40px;
background:#ff7200;
position:relative;
overflow:hidden;
text-align:center;
line-height:40px;
}
input{
position:absolute;
right:0;
top:0;
font-size:100px;
opacity:0;
filter:alpha(opacity=0);
}
</style>
<body>
<a href="#">
<input type="file" value="文件" />选择文件
</a>
</body>
</html>
下面图片样式:
.filename{
width:245px;
height:28px;
line-height:28px;
font-size:14px;
color:#686868;
text-indent:5px;
border:solid 1px #cbcbcb;
border-right:none;}
a{
display:inline-block;
position:relative;
top:1px;
width:93px;
height:30px;
line-height:30px;
font-size:16px;
text-align:center;
color:#fff;
background:#ff7200;
text-decoration:none;
}
.fileupload{
position:absolute;
right:0;
top:0;
font-size:100px;
opacity:0;
filter:alpha(opacity=0);
}
<input type="text" class="filename"/>
<a>
<input type="file" class="fileupload" id="file_upload" name="imgUrl" />选择文件
</a>