Default upload style We always feel not very good, according to the needs of the total want to change to and the structure of the unified style ...
Implementation methods and ideas: 1. In the input element plus a hyperlink label 2. Set the button style for the A tag 3. Set input[type= ' file ' to be transparent and positioned to cover on a
HTML code:
<class= "Input-file input-fileup" href= "javascript:;" > + Select File <size= " +" type= "File" name = "File" ID = "File" > </ a >
CSS code:
. Input-file{Display:Inline-block;position:relative;Overflow:Hidden;text-align:Center;width:Auto;Background-color:#2c7;Border:Solid 1px #ddd;Border-radius:4px;padding:5px 10px;font-size:12px;Font-weight:Normal;Line-height:18px;Color:#fff;text-decoration:None;}. Input-file input[type= "file"]{position:Absolute;Top:0; Right:0;font-size:14px;Background-color:#fff;Transform:Translate ( -300px, 0px) scale (4);Height:40px;Opacity:0;Filter:Alpha (opacity=0); }
Effect:
The uploaded file name can not be displayed at this time, if you want to display the uploaded filename need js to handle
JS Code:
<script> $(function(){ $(". Input-fileup"). On ("Change", "input[type= ' file ']",function(){ varfilepath=$ ( This). Val (); if(Filepath.indexof ("jpg")!=-1 | | filepath.indexof ("PNG")!=-1){ $(". FileerrorTip1"). HTML (""). Hide (); varArr=filepath.split (' \ \ '); varFilename=arr[arr.length-1]; $(". ShowFileName1"). HTML (fileName); }Else{ $(". ShowFileName1"). HTML (""); $(". FileerrorTip1"). HTML ("You did not upload the file, or you uploaded a file of the wrong type!"). "). Show (); return false } }) }) </script>
Also need to add two div to HTML
<aclass= "Input-file input-fileup"href= "javascript:;">+ Select File<inputsize= "+"type= "File"name= "File"ID= "File"></a>
<Divclass= "FileerrorTip1"></Div><Divclass= "ShowFileName1"></Div>
Effect:
input[tyle= "file"] style modification and upload file name display