views:

1299

answers:

4

Is there a way to style (or script) <input type=file /> element to have visible only "Browse" button without text field?

Thanks

Edit: Just to clarify why to I need this. I'm using multi file upload code from http://www.morningz.com/?p=5 and it doesn't need input text field because it never has value. Script just adds newly selected file to collection on page. It would look much better without text field, if it's possible.

+6  A: 

That's going to be very hard. The problem with the file input type is that it usually consists of two visual elements, while being treated as a single DOM-element. Add to that that several browsers have their own distinct look and feel for the file input, and you're set for nightmare. See this article on quirksmode.org about the quirks the file input has. I guarantee you it won't make you happy (I speak from experience).

[EDIT]

Actually, I think you might get away with putting your input in a container element (like a div), and adding a negative margin to the element. Effectively hiding the textbox part off screen. Another option would be to use the technique in the article I linked, to try to style it like a button.

Erik van Brakel
That article on quirksmode is great. Styling file inputs are still a pain though. :P
MitMaro
I don't think the contained netagive-margin will work well once you take into account different browser styles and minimum font sizes being different from user to user.
joebert
joebert: I agree, I think the best option is still the technique displayed in the quirksmode article, how painfully hackish...
Erik van Brakel
A: 

Ive a really hacky solution with this...

<style type="text/css"> 
    input[type="file"]
    { 
        width: 80px;        
    } 
</style>

<input id="File1" type="file" />

The problem is the width attribute that is hiding the text field will obvously vary between browsers, vary between Windows XP themes and so on. Maybe its something you can work with though?...

Chalkey
Even this one won't work on IE6, the browser doesn't understand attribute selectors.
Adrian Godong
Ah, oh well nevermind :)
Chalkey
Doesn't seem to work in FF 3.6.6 either
Shoan
A: 

The quirksmode trick will hide the text field but you are stuck having a text selection character over a button which is the problem I have, setting the cursor css style wont work either :(

Paramiliar
A: 

RESOLVED <div style="overflow: hidden;width:83px;"> <input style='float:right;' name="userfile" id="userfile" type="file"/> </div>

druveen