8

Following the CSS style trick from this question I was able to create a custom upload button. Now, the challenge is to make the entire portion of the button change the mouse pointer icon to the hand one.

The way I partially achieved this can be seen here (jSFiddle). As you can see, the cursor only appears to be a hand while hovering the right area of the the button (I'm in the latest version of firefox).

The css (also on jSFiddle)

 <span id="uploadMask">
    <input type="file" multiple="multiple" name="file" id="file_upload">
     <span class="button">Select Documents</span>
 </span>

The css (also on jSFiddle)

#uploadMask {
  width:160px;
  display: block;
  float:left;
  overflow: hidden;
  height:32px;
  margin-right: 5px;
  position: relative;
}

#uploadMask input {
  position: absolute;
  top:0;
  bottom: 0;
  right:0;
  opacity: 0;
  z-index: 2;
  cursor: pointer;
}

#uploadMask .button {
  background:#ccc;
  line-height:24px;
  padding:5px 15px;
  display:block;
}

Any ideas?

Community
  • 1
  • 1
Vlad Nicula
  • 3,577
  • 6
  • 32
  • 50

2 Answers2

7

There's nothing you can do it seems to get the cursor property to work on the "text" portion of <input type="file">, but the "button" part does display the hand pointer.

http://jsfiddle.net/gN2JM/17/

enter image description here

No hand cursor on the red part!

Borrowing from the solution to this question:

Is there a way to make the native `browse` button on a file input larger cross browser?

You can enlarge the button size by adding:

#uploadMask input {
    font-size:200px; /* Any high number to guarantee it's big enough,
                        overflow:hidden on the parent takes care of the rest */
}

http://jsfiddle.net/gN2JM/15/

Community
  • 1
  • 1
Wesley Murch
  • 101,186
  • 37
  • 194
  • 228
1

If you take off the opacity: 0;, you'll see why there is a place where the cursor:pointer doesn't show up. http://jsfiddle.net/gN2JM/13/ Whenever you are moused over the actual button, it gives the regular cursor.

Use THIS for a solution that supposedly works all the time, or just set the position of the button to go off the edge of the screen>> http://jsfiddle.net/gN2JM/14/

Community
  • 1
  • 1
Isaac Fife
  • 1,659
  • 13
  • 15