About input file control and beautification

About input file control and beautification

When uploading on some websites, after clicking the "Browse" button, the [Select File] dialog box will pop up. To achieve this function, just use the input file control~

XML/HTML CodeCopy content to clipboard
  1. <!doctype html >     
  2. < html   lang = "en" >     
  3. < head >     
  4.    < meta   charset = "UTF-8" >     
  5.    < title > Document </ title >     
  6.    < style > </ style >     
  7. </ head >     
  8. < body >     
  9.   < input   type = "file"   value = "Select file"   />     
  10. </ body >     
  11. </ html >     

The effect picture is like this:

Notice! Don't think this is composed of a text and a button, it is actually a file control.

Today, I encountered a requirement at work: do not display "No file selected". After tinkering with it for an hour, I found that setting its width value solved it:

Code: <input type="file" value="Select file" />

The width value is set to 70px, as shown below:

【beautify】

Ideas:

The outer div is to provide a position reference for the input inside, because relative positioning is required when writing styles, so that the real file control covers the simulated one, and then hides the file control (even if the file control is not visible)

XML/HTML CodeCopy content to clipboard
  1. <!doctype html >   
  2. < html   lang = "en" >   
  3. < head >   
  4.    < meta   charset = "UTF-8" >   
  5.    < title > Document </ title >   
  6.    < style >   
  7. .file-box{ position:relative;width:340px}
  8. .txt{ height:22px; border:1px solid #cdcdcd; width:180px;}
  9. .btn{ background-color:#FFF; border:1px solid #CDCDCD; height:24px; width:70px;}
  10. .file{ position:absolute; top:0; right:80px; height:24px; opacity:0;width:260px; }
  11.    </ style >   
  12. </ head >   
  13. < body >   
  14.      < br > < br >   
  15.      < div   class = "file-box" >     
  16.          < form   action = ""   method = "post"   enctype = "multipart/form-data" >     
  17.          < input   type = 'text'   name = 'textfield'   id = 'textfield'   class = 'txt'   />     
  18.          < input   type = 'button'   class = 'btn'   value = 'browse'   />     
  19.          < input   type = "file"   name = "fileField"   class = "file"   id = "fileField"   size = "28" />     
  20.      </ form >     
  21.      </ div >     
  22. </ body >   
  23. </ html >   

Effect:

The above article about input file controls and beautification is all the content that the editor shares with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

<<:  JavaScript data transmission between different pages (URL parameter acquisition)

>>:  Example of implementing QR code scanning effects with CSS3

Recommend

A brief introduction to the usage of decimal type in MySQL

The floating-point types supported in MySQL are F...

Implementation of breakpoint resume in Node.js

Preface Normal business needs: upload pictures, E...

MySQL transaction analysis

Transaction A transaction is a basic unit of busi...

How to draw a mind map in a mini program

Table of contents What is a mind map? How to draw...

How to use vue-cli to create a project and package it with webpack

1. Prepare the environment (download nodejs and s...

MySQL cross-database transaction XA operation example

This article uses an example to describe the MySQ...

How to set a dotted border in html

Use CSS styles and HTML tag elements In order to ...

How to install MySQL 5.7 on Ubuntu and configure the data storage path

1. Install MySQL This article is installed via AP...

Problem record of using vue+echarts chart

Preface echarts is my most commonly used charting...

Vue SPA first screen optimization solution

Table of contents Preface optimization SSR Import...

Introduction to JavaScript array deduplication and flattening functions

Table of contents 1. Array flattening (also known...

Install two MySQL5.6.35 databases under win10

Record the installation of two MySQL5.6.35 databa...