When we want to beautify the form with css, there are two controls that will be different from those of the former, one is the well-known select, the other is the inputtypefile that I want to talk about now. Why do we need to beautify the file control? Imagine that other children are dressed neatly and beautifully. Two of them are not so harmonious.
The original file control is as follows:
Do not think that this is composed of a text and a button. It is a control and the html code is:
The Code is as follows:
In this case, we use a text and a button to display the file style. The html code is as follows:
The Code is as follows:
A layer of p outside is used to provide location reference for the input, because relative positioning is required during writing, so that the real file control overwrites the simulation, then the file control is hidden (even if the file control is invisible), so the css code is as follows:
The Code is as follows:
. File-box {position: relative; width: 340px}
. Txt {height: 22px; border: 1px solid # cdcdcd; width: 180px ;}
. Btn {background-color: # FFF; border: 1px solid # CDCDCD; height: 24px; width: 70px ;}
. File {position: absolute; top: 0; right: 80px; height: 24px; filter: alpha (opacity: 0); opacity: 0; width: 260px}
:
Last, leave a DEMO: Click to view the demo.
<! DOCTYPE html> <pead> <meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8 "/> <title> define the input type =" file "style </title> <style type =" text/css "> body {font-size: 14px;} input {vertical-align: middle; margin: 0; padding: 0 }. file-box {position: relative; width: 340px1_.txt {height: 22px; border: 1px solid # cdcdcd; width: 180px ;}. btn {background-color: # FFF; border: 1px solid # CDCDCD; height: 24px; width: 70px ;}. file {position: absolute; top: 0; right: 80px; height: 24px; filter: alpha (opacity: 0); opacity: 0; width: 260px} </style> </pead> <body> <p class = "file-box"> </p> </body> </ptml>