Why isn't there a fancy file element upload button for twitter bootstrap? It would be sweet if the blue primary button was implemented for the upload button. Is it even possible to finesse the upload button using CSS? (seems like a native browser element that can't be manipulated)
相关问题
- Laravel Option Select - Default Issue
- HTML form is not sending $_POST values
- How to use Control.FromHandle?
- Adding a timeout to a render function in ReactJS
-
Why does the box-shadow property not apply to a
This works perfectly for me
I have the same problem, and i try it like this.
The CSS
The JS
Hope you found the best solution...
In respect of claviska answer - if you want to show uploaded file name in a basic file upload you can do it in inputs'
onchange
event. Just use this code:This jquery JS code is responsible will retrieving uploaded file name:
Or with vanilla JS:
No fancy shiz required:
HTML:
JS:
CAUTION: The three form elements in question MUST be siblings of each other (.image-file-chosen, .image-file-button, .image-file)
Here's a solution for Bootstrap 3 and 4.
To make a functional file input control that looks like a button, you only need HTML:
HTML
This works in all modern browsers, including IE9+. If you need support for old IE as well, please use the legacy approach shown below.
This techniques relies on the HTML5
hidden
attribute. Bootstrap 4 uses the following CSS to shim this feature in unsupportive browsers. You may need to add if you're using Bootstrap 3.Legacy approach for old IE
If you need support for IE8 and below, use the following HTML/CSS:
HTML
CSS
Note that old IE doesn't trigger the file input when you click on a
<label>
, so the The CSS "bloat" does a couple things to work around that:<span>
Feedback & Additional Reading
I've posted more details about this method, as well as examples for how to show the user which/how many files are selected:
http://www.abeautifulsite.net/whipping-file-inputs-into-shape-with-bootstrap-3/
With some inspiration from other posts above, here is a full solution that combines what looks like a form-control field with an input-group-addon for a clean file input widget that includes a link to the current file.