初始样式效果:
这种效果在不同浏览器中显示的还不相同.下面我们开始对其进行美化:
基本思路:先将之前按钮的透明度opacity设置为0,然后,在外层用div遮盖,就实现了美化功能。
实现代码:
1.html代码段:
<form action="" method="post">
<a href="javascript:;" class="file">选择文件
<input type="file" name="" id="">
</a>
<input type="submit" value="上传文件">
</form>
2.css代码段:
<style type="text/css">
.file {
position: relative;/*绝对定位!*/
display: inline-block;/*设置为行内元素*/
background: #D0EEFF;
border: 1px solid #99D3F5;
border-radius: 4px;
padding: 4px 12px;
overflow: hidden;
color: #1E88C7;
text-decoration: none;
text-indent: 0;
line-height: 20px;
}
.file input {
position: absolute;/*相对定位*/
right: 0;
top: 0;
opacity: 0;/*将上传组件设置为透明的*/
font-size: 100px;
}
.file:hover {
background: #AADDFF;
border-color: #78C3F3;
color: #004974;
text-decoration: none;
}
</style>
3.美化后的效果图:
这种美化低版本浏览器可能不支持!
我也是刚刚用到的,希望对大家有所帮助,