input file上传按钮的美化思路是,先把之前的按钮透明度opacity设置为0,然后,外层用div包裹,就实现了美化功能。
主要有两点需要做:
- 将input type=file控件透明
- 将input type=file控件放置text和button组合上,必须保持input type=file控件与text和button组合大小一致,位置完全重合。
下面贴上代码:
html代码:
<label class=\"fileContainer\">
Click here to trigger the file uploader!
<input type=\"file\"/>
</label>
css代码:
.fileContainer {
overflow: hidden;
position: relative;
background: #ccc;
border-radius: .5em;
float: left;
padding: .5em;
}
.fileContainer [type=file] {
display: block;
font-size: 999px;
filter: alpha(opacity=0);
min-height: 100%;
min-width: 100%;
opacity: 0;
position: absolute;
right: 0;
text-align: right;
top: 0;
cursor: pointer;
}
如需查询运行效果,可点击这里
继续阅读与本文标签相同的文章
上一篇 :
js中什么时候需要使用CDATA
下一篇 :
大脑升维:人工智能浪潮下的适者生存之道
-
性能优化之卡顿延迟
2026-05-14栏目: 教程
-
第16问:Filecoin从DSN角度解读
2026-05-14栏目: 教程
-
C/C+从零基础到精通,究竟是如何快速完成的?其实只需要这6步!
2026-05-14栏目: 教程
-
谷歌再爆重大安全漏洞!华为却成最大赢家?网友:这谁还敢用!
2026-05-14栏目: 教程
-
Excel崩溃文件如何找回
2026-05-14栏目: 教程
