最近做一套手机商城页面,在退款申请页面有上传图片显示缩略图的功能,以前没有做过这个,所以整理了一下。
HTML :
<p>上传图片:</p>
<div id="imgPreview"></div>
<span class="upload-img"><input id="fileUpload" accept="image/*" type="file" multiple="multiple"></span>
</div>
CSS :
#imgPreview {
float: left;
border: none;
}
#imgPreview img {
margin-right: 10px;
width: 50px;
height: 50px;
}
.upload-img {
display: block;
float: left;
width: 50px;
height: 50px;
overflow: hidden;
position: relative;
background: url("../images/self/upload.png") no-repeat 0;
background-size: contain;
}
//这儿是为了改变上传按钮样式把input设为了透明色
.upload-img input {
height: 50px;
opacity: 0;
filter: alpha(opacity=0);
position: absolute;
top: 0;
right: 0;
}
在这里我把上传按钮inp