How can I style a file input field in Firefox?

后端 未结 6 947
Happy的楠姐
Happy的楠姐 2020-11-28 09:32

I am currently doing the front end for a site with looooads of forms, all styled up and looking pretty in IE, but I\'ve just noticed that in Firefox the file input fields ar

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-28 10:00

    Many of the answers above are quite old. In 2013 a much simpler solution exists: nearly all current browsers...

    • Chrome
    • IE
    • Safari
    • Firefox with a few-line fix

    pass through click events from labels. Try it here: http://jsfiddle.net/rvCBX/7/

    • Style the however you you would like your file upload to be.
    • Set for="someid" attribute on the label
    • Create a element, that's hidden.

    Clicking the label will passthrough the event to the fileupload in Chrome, IE, and Safari.

    Firefox requires a very small workaround, which is detailed in this answer.

提交回复
热议问题