Replace input type=file by an image

后端 未结 13 2097
感动是毒
感动是毒 2020-12-02 04:13

Like a lot of people, I\'d like to customize the ugly input type=file, and I know that it can\'t be done without some hacks and/or javascript. But,

13条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-02 04:41

    I have had lots of issues with hidden and not visible inputs over the past decade sometimes things are way simpler than we think.

    I have had a little wish with IE 5,6,7,8 and 9 for not supporting the opacity and thus the file input would cover the upload image however the following css code has resolved the issue.

    -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
    filter: alpha(opacity=0);  
    

    The following snipped is tested on chrome, IE 5,6,7,8,9,10 the only issue in IE 5 is that it does not support auto margin.

    Run the snippet simply copy and paste the CSS and HTML modify the size as you like.

    .file-upload{
    	height:100px;
    	width:100px;
    	margin:40px auto;
    	border:1px solid #f0c0d0;
    	border-radius:100px;
    	overflow:hidden;
    	position:relative;
    }
    .file-upload input{
    	position:absolute;
    	height:400px;
    	width:400px;
    	left:-200px;
    	top:-200px;
    	background:transparent;
    	opacity:0;
    	-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
    	filter: alpha(opacity=0);  
    }
    .file-upload img{
    	height:70px;
    	width:70px;
    	margin:15px;
    }

提交回复
热议问题