CSS Input[type=file] style beautification, input upload button beautification

Source: Internet
Author: User

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.


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 }})              
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

CSS Input[type=file] style beautification, input upload button beautification

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.