您的位置:首页 > Web前端 > CSS

`<input type="file">`的样式重置问题

2017-02-21 16:06 465 查看

<input type="file">
的样式重置简单方法

HTML部分

<label for="">
<span></span>
<input  type="file" multiple accept="image/jpeg,image/png,image/gif,image/bmp">
</label>


span用于设置上传图片的照相机Icon等。

input 的accept属性表示支持何种格式的文件(后缀),multiple代表支持多个文件上传。

CSS样式

核心:使本来的input元素的opacity为0且占满整个父元素(可能是某个div),使得点击这个div均可以触发点击效果。

input[type=file]{
position: absolute;
left: 0;
top: 0;
opacity: 0;
height: 100%;
width: 100%;
}


增强 : 加上一个居中照相机icon

给span进行修饰

.classname span{
position: absolute;
left: 0;
right: 0;
top: 50%;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  input file css