CSS Input[type=file] style beautification, input upload button beautificationAugust 29, 2014Http://www.haorooms.com/post/css_input_uploadmh
Because tomorrow the company organizes out to play, today the two days of the blog are written, today's content is input[type=file] style beautification, input upload button beautification.
When we do input text upload, HTML comes with the upload button is ugly, how to beautify it? Similarly: input checkbox Landscaping, Input Radio Landscaping is a reason, the article will be summarized later.
Ideas:
The beautification idea of the input File Upload button is to set the previous button transparency opacity to 0, and then wrap the outer layer with a div to achieve the beautification function.
The code is as follows:
DOM Structure:
<a href="javascript:;" class="A-upload"> <input type="File" name="" ID="">Click here to upload the file</a><a href="javascript:;" class="File">Select File<input type="File" name="" ID=""></a>
CSS Style 1:
/*a upload * /.a-Upload{padding: 4px 10px;Height: 20px; Line-Height: 20px;position:relative;cursor:Pointer;Color: #888;background: #fafafa;Border: 1pxSolid#ddd;Border-radius: 4px;Overflow:Hidden;Display: inline-Block; *Display: inline; *Zoom: 1}.a-Upload Input{position:Absolute;Font-size: 100px; Right: 0;Top: 0;Opacity: 0;Filter:Alpha(Opacity=0);cursor:Pointer}.a-Upload:Hover{Color: #444;background: #eee;Border-Color: #ccc;text-Decoration:None}
Style 2:
.file{position:relative;Display: inline-Block;background: #D0EEFF;Border: 1pxSolid#99D3F5;Border-radius: 4px;padding: 4px 12px;Overflow:Hidden;Color: #1E88C7;text-Decoration:None;text-Indent: 0; Line-Height: 20px;}.file Input{position:Absolute;Font-size: 100px; Right: 0;Top: 0;Opacity: 0;}.file:Hover{background: #AADFFD;Border-Color: #78C3F3;Color: #004974;text-Decoration:None;}
The following changes are followed:
Style Two:
Note : For HTML5 input:file, you can also control the type of upload, but this is HTML5, the lower version of the browser is not supported, the details see: HTML5 input:file Upload type control/HTTP/ Www.haorooms.com/post/input_file_leixing
Display file name after landscaping
The above landscaping, the default display of the file name is also hidden, then how to display the file name? It doesn't matter, we can use jquery to get the file name.
We can write a change event.
$(". A-upload"). on("Change","input[type= ' file ']",function(){ varFilePath=$( This).Val(); if(FilePath.indexOf("JPG")!=-1 ||FilePath.indexOf("PNG")!=-1){ $(". Fileerrortip").HTML("").Hide(); vararr=FilePath.Split(' \ \ '); varFileName=arr[arr.length-1]; $(". Showfilename").HTML(FileName); }Else{ $(". Showfilename").HTML(""); $(". Fileerrortip").HTML("You did not upload the file, or you uploaded a file of the wrong type!" ").Show(); return false }})
Other Input Landscaping Articles
About the Input checkbox and radio styling, I also wrote an article, see Http://www.haorooms.com/post/css_mh_ck_radio
There is a http://www.haorooms.com/post/qd_ghfx on the right side of input search, you can see the fifth article.
Related articles:
- CSS input checkbox and radio style beautification
- Input file Upload, JS control the size and format of uploaded files
- HTML5 input:file Upload Type control
- Application techniques of Box-shadow in CSS
- CSS variables and inheritance
- Talk about some magical usages of inline-block.
- Some views on mobile development of popular unit REM
- Summary of the less commonly used effects of CSS
- CSS paragraph text (mixed in English and Chinese) for both ends of the alignment
CSS Input[type=file] style beautification, input upload button beautification