html file自定义文本框,【原创】自定义input file ---工作总结

先上图吧~

f0101fe93c9487ec9ad8bc81b9badb05.png

样式OK,测试功能正常。

思路:

隐藏系统原本的input file,使用css的opacity等属性

然后,提高input file的 z-inde 值

给input file 做一个 onchange事件,将值传给 input text 里。

在透明的整个input file区域 上面,做一个文本框和按钮。

技巧:

input file 虽然被透明,但是点击上传并不会消失;

注意提升input file 的z-index值,否则,点击上传不会出来。

css如下:

/*自定义input-file上传样式*/

.otoc-uploadfile-box{

position: relative;

width: 100%;

height: 36px;

box-sizing: content-box;

}

.otoc-uploadfile-box > input[type=file]{

position: absolute;

top: 0;

left: 0;

filter: alpha(opacity:0);

opacity: 0;

width: 100%;

height: 36px;

cursor: pointer;

z-index: 2;

}

.otoc-uploadfile-box > input[type=text]{

position: absolute;

top: 0;

left: 0;

padding-left: 3px;

width: 75%;

height: 36px;

border: 1px solid #ccc;

z-index: 0;

}

.otoc-uploadfile-box > button[type=button]{

position: absolute !important;

top: 0;

right: 0;

width: 25%;

height: 36px;

z-index: 0;

color: #fff;

background-color: #36c6d3;

border:1px solid #2bb8c4;

user-select:none;

}

css如下:

浏览文件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值