If I remember correctly, HTML5 allows you to call the click
method on a hidden input element to show the file dialog via a custom button (why not just make it work without an element, I don't know). Unfortunately not all currently in use browsers support this yet, so you're stuck with styling a file input to look like a button.
This is a hilariously ugly but ingenious CSS hack I came across on a site once (probably imgur):
.fileupload {
width: 100px;
height: 50px;
position: relative;
overflow: hidden;
background: ...; /* and other things to make it pretty */
}
.fileupload input {
position: absolute;
top: 0;
right: 0; /* not left, because only the right part of the input seems to
be clickable in some browser I can't remember */
cursor: pointer;
opacity: 0.0;
filter: alpha(opacity=0); /* and all the other old opacity stuff you
want to support */
font-size: 300px; /* wtf, but apparently the most reliable way to make
a large part of the input clickable in most browsers */
height: 200px;
}
And the HTML to go with it:
<div class="fileupload">
<input type="file" />
Any content here, perhaps button text
</div>
What it does is it makes the file input itself enormous (by changing the font size (!?)) to ensure it covers the button, and then cuts off the excess with overflow: hidden;
. This may not work for absolutely enormous buttons.