The input type = "file" in the form is often used in front-end development, but it is unfortunate that the input type = "file" is not uniform in various browsers, and style is difficult to work;
Usually, my designers are very beautiful. If you really want to restore the design draft, you can only use text boxes and buttons to simulate an input type = "File ".
The HTML code is as follows:
<div class="type-file-box">
<form action="" method="post" name="form1" id="form1">
<input name="fileField" type="file" id="fileField" size="28" />
</form>
</div>
This is a basic input type = "File ". Of course, you may not see the code of the text box and button here. We can append the text box and button to HTML in the following Js.
Note: size = "28" is the width and height of input type = "file" in Firefox cannot be defined by style, therefore, the size attribute is used to control the width of input type = "File ".
The CSS code is as follows:
.type-file-box {
position:relative;
width:260px
}
input {
vertical-align:middle;
margin:0;
padding:0
}
.type-file-text {
height:22px;
border:1px solid #cdcdcd;
width:180px;
}
.type-file-button {
background-color:#FFF;
border:1px solid #CDCDCD;
height:24px;
width:70px;
}
.type-file-file {
position:absolute;
top:0;
right:0;
height:24px;
filter:alpha(opacity:0);
opacity: 0;
width:260px
}
Note: here, the filter: alpha (opacity: 0); opacity: 0 indicates that
Type = "file" is completely transparent, so that the user cannot see the input
Type = "file ". The level is above the text box and button. In this way, when you click the button, the input type = "file" is actually clicked. js code:
$ (Function (){
VaR textbutton = "<input type = 'text' name = 'textfield 'id = 'textfield 'class = 'Type-file-text'/> & nbsp; <input type = 'submit 'name = 'button 'id = 'button 'value = 'browse... 'class = 'Type-file-click'/>"
$ (Textbutton). insertbefore ("# filefield ");
$ ("# Filefield"). Change (function (){
$ ("# Textfield"). Val ($ ("# filefield"). Val ());););
Here we use the JQ when the input type = "file" value onchange when the value of the text box is set to input type = "file" value, OK the demo Demo: http://www.css88.com/demo/input-file/
Statement: This article uses BY-NC-SA protocol for authorization | Web Front-end development
Reprinted, please refer to "simulate input type = file"