CSS Input[type=file] style beautification, input upload button Landscaping August 29, 2014 113,210 views
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" >< Span class= "PLN" > Select file <input type=< Span class= "ATV" > "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}.-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;}.:hover { background : #AADFFD; Border-< Span class= "PLN" >color: #78C3F3; color< Span class= "pun" >: #004974; Text-decoration: None; /span>
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 ( ( "You did not upload the file, or you uploaded a file of the wrong type!" "show (); return false }})
Input file Beautification method