This question already has an answer here:
- Styling an input type=“file” button 39 answers
Simple question... How do I change the cursor type on a file input type?
I've tried the following:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<style>
input[type="file"] {
cursor: pointer;
}
</style>
</head>
<body>
<input type="file">
</body>
</html>
For some reason, it won't play ball.
Based on https://stackoverflow.com/a/3030174/2325676 - Hide the input using opacity 0.
The key to getting the cursor to work on the entire area is setting the
font-size
to a value greater than the height of the button so that the file input button is pushed below the visible area and the mouse hover is on the text part of the file input:How I did it:
And then on my view page:
And then I simply submit my form via AJAX to the server and handle the rest there.
So tl;dr -> I relay the click of the visible link (with all styles and bells and whistles) and I actually click the file input. :)
Hope this helps someone.
If you're trying to do Ajax uploader, you might try another technique for compatible browsers such as FireFox and Chrome. They support triggering a click event on totally invisible file input. You can hide file input in any way you want except setting it's display property to none. Setting { height: 0; overflow: hidden } on parent form will do the trick. I use separate forms for each uploader.
Redirect your custom button click event to hidden file input and you're done.
To use this technique you must perform navigator.userAgent check for Gecko or WebKit engine. For other engines you have to use old transparent file input method.
If you want to force the cursor to be hand in order to put it on an image, here is a
SIMPLE WAY AND HOW IT WORKS IN ALL BROWSERS:
HTML:
JQuery:
Then you can press on any button to upload file, and you have a pointer cursor .
In Chrome and Opera the cursor becomes a pointer on the padding only and if
display:block;
, that's why for those browsers you should do this:I met this issue today and with:
It seems to do fine :-)
I found out that there's another approach to make it. Works perfectly in Opera New, FF, Chrome and Safari. Unfortunately it doesn't work perfect in IE (but good enough for my case).
The idea is to wrap
input=file
element with fixed size div and hidden overflow and setcursor: pointer;
. Than we move button outside of the div using left padding.and sample styles
Here you can find live example: http://jsfiddle.net/5c5RH/2/