How do you style an input type=\"file\"
button?
All rendering engines automatically generate a button when an is created. Historically, that button has been completely un-styleable. However, Trident and WebKit have added hooks through pseudo-elements.
Trident
As of IE10, the file input button can be styled using the ::-ms-browse
pseudo-element. Basically, any CSS rules that you apply to a regular button can be applied to the pseudo-element. For example:
::-ms-browse {
background: black;
color: red;
padding: 1em;
}
This displays as follows in IE10 on Windows 8:
WebKit
WebKit provides a hook for its file input button with the ::-webkit-file-upload-button
pseudo-element. Again, pretty much any CSS rule can be applied, therefore the Trident example will work here as well:
::-webkit-file-upload-button {
background: black;
color: red;
padding: 1em;
}
This displays as follows in Chrome 26 on OS X: