Open rubinahaddad opened 10 years ago
Not really possible as the "Choose file" button is dynamically generated by the browser so we can't apply the Bootstrap markup and CSS to it. That is the same reason why we can't change the button text, or make it specific to the language of the page (browsers make it specific to the language of the browser).
@pjackson28 There appears to be a few alternatives that can solve this problem: http://stackoverflow.com/questions/21842274/cross-browser-custom-styling-for-file-upload-button
Interesting!!! http://jsfiddle.net/sv32N/
Great find @burgvan
The problem with that approach is it forces a button-only approach across all browsers. So for instance the area that actually shows the name of the selected file will be lost. We should not be diminishing native functionality in the name of consistency.
This would be an excellent candidate for the Shadow DOM.....maybe one day
Well you can use JavaScript to show the name of the selected file too. Here's an example I found: http://geniuscarrier.com/how-to-style-a-html-file-upload-button-in-pure-css/
Browser support for the Shadow DOM is coming but we still have a long way to go for cross-browser support (http://caniuse.com/shadowdom). There are some possible future polyfills (https://github.com/Polymer/ShadowDOM) but they may come with a fairly significant performance cost.
So I don't see there being a solution to this issue in the near future but perhaps someday down the road.
@burgvan The problem is that we effectively have to code a full replacement for native functionality, including forcing DOM changes through JavaScript. That is a lot of support effort and fakery to just override the default appearance of input type="file". We would also have to tackle WAI-ARIA support, and test extensively, to make this behave correctly on screen readers (and would have to have JavaScript running on every page to check for the existence of input type="file").
I don't think it is a good idea to proceed with any of this unless we can find a CSS-only solution that does not negatively impact end users.
It seems WebKit has a Shadow DOM already for it: -webkit-file-upload-button
Yes, Chrome added Shadow DOM support a while back as did Opera. A few other browsers added support recently (or will very soon) but there are still very noticeable omissions such as IE, Safari and iOS Safari which don't have support in any version and there is no clear indication as to when that support will be added.
Actually, IE 10 has it. Firefox surprisingly doesn't
From HE: #29
Problem: In Basic Example, the ‘Submit’ button’s visual design differs from the nearby ‘Choose File’ button and they from other buttons on the page, for no obvious reason.
Suggestion: Use consistent styling everywhere.