tags:

views:

3377

answers:

3

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"&gt;
<html>
    <head>
        <style>
            input[type="file"] {
              cursor: pointer;
            }
        </style>
    </head>
    <body>
        <input type="file">
    </body>
</html>

For some reason, it won't play ball.

+1  A: 

First of all, your code works on Internet Explorer, but doesn't on Firefox.

Second, W3C Css standard doesn't allow styling complex tags like <input />. Even for cursor property.

Endly, see this page. I did not try his solution, so tell us if it works and how.

enguerran
The solution you point to does a trick to hide the file input so you can display your own look, but keep the mouse interactive stuff provided by the file input control. That means that the mouse pointer still is affected by the file input, and it doesn't help a bit. I also tried the other way around, and used onclick event on a div that covered the file input. This solved the cursor issue, but in FireFox the fileInput.click() method didn't work. It actually works in IE but that doesn't help us here...
awe
+4  A: 

It works differently in different browsers. I guess it's because the file input type is quite special.

What browser/version do you use?

I know that IE6 does not support to specify the type in the style.

How it works in the different browsers

IE7+

Works perfectly

FireFox

Does not work at all.

Chrome and Safari (identical behavior)

Uses arrow over the button, but your defined cursor over the rest.

Opera

Uses your defined cursor when entering any part from outside the input element, but the default cursor is used when moving mouse internally between text field and button (text cursor over the text field, and arrow over the button).

awe
im in the "does not work at all" category!!! Thank you for this feedback. Should have checked really.
Tisch
the problem does not only come from [type] behavior.
enguerran
Firefox 3.5 can go to hell for now!
Tisch
@enguerran: You are right. It is only IE6 that has problem with that. The issues for the others are only related to setting the cursor style for the ´<input type="file"/>` element, regardless of setting it in a global style section/file, or in a style parameter directly on the html tag.
awe
+1  A: 

Try using:

input[type=file] {
  cursor: pointer; cursor: hand;
}

See if that works. I've had to put pointer + hand in mine to make it work in FF/Chrome/etc. Also, I'm not sure if it matters but I don't think there are quotes around 'file' in the css.

Jesse O'Brien
This is not right. `cursor:hand` is supported only by some browsers (not including Firefox). `cursor: pointer` is the official standard, and is supported by all browsers.
awe
@awe: "cursor: hand" is supported on firefox, but maybe not on input tag which does not allow any style on firefox.@Jesse O'Brien: what a strange idea to have a doublon here. Any explanation about this magical instruction?
enguerran
Quotes around "file" is optional. It works either way. The problem is that Firefox does not support setting cursor on the input file element.
awe
@enguerran: I said this based on testing in **Firefox** version 3.5.3: I tried to set `cursor:pointer` on a div tag, and it worked. Then I tried to set `cursor:hand` and it didn't work.
awe
I have DOCTYPE set to `XHTML 1.0 Strict` in my test html file.
awe
@enguerran Not sure, I just stumbled upon it one day, I'm pretty sure I forgot to delete the pointer and added the hand line and it started working. @awe try using the cursor: pointer; cursor: hand;
Jesse O'Brien
@Jesse O'Brien: The issue here is that Firefox does not support setting cursor at all on the `input[type=file]` element. It has nothing to do with using `pointer` and/or `hand`. It works for input buttons by setting the cursor for `input[type=button]`. And yes, for others than `input[type=file]`, it works with setting `cursor: pointer; cursor: hand;`, but that is because Firefox ignores the invalid `cursor: hand;` and falls back to the previous set `cursor: pointer;`. If you set **only** `cursor: pointer;', it also works, and if you set **only** `cursor: hand;` it does not work.
awe
Thanks for clearing that up awe! :o)
Tisch