Apply CSS Style to Browse Button
Filed in: Web Development — April 8th, 2004
There are situation that you may want to apply CSS formating to a <input type="file"> tag (Browse button, allow user to select file). However, you will found that CSS does not work on it when you try to apply CSS. You do nothing wrong, it is nature of the CSS2.
Here is the workaround sample code:
<input name="browse" type="file" style="display: none;">
<input name="file" type="text">
<input name="Submit" type="submit" class="button" value="Browse" onClick="document.form1.browse.click(); document.form1.file.value=document.form1.browse.value; return false;">
<input name="upload" type="submit" class="button" value="Upload" onclick='document.form1.browse.disabled=true;'>
Note:
This code is supported by Internet Explorer only, due to the IE custom method – click(). There is solution for Netscape and Mozilla at here, but I haven’t try it out yet.


