Normally, you can't use CSS to style HTML file inputs. They'll always look fugly. With jQuery Fileinput you can!
By wrapping the file input on a div, adding a replacement element to provide the visuals and then making the original input invisible. Clicks to the replacement element are propagated to the original input on the browsers that support it, otherwise a transparent file input is placed on top of the replacement.
...
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript" src="https://raw.github.com/javanto/jquery-fileinput/3.1.0/dist/jquery.fileinput.min.js"></script>
<script type="text/javascript">
//<![CDATA[
$().ready(function() {
$("input[type=file]").fileinput();
});
//]]>
</script>
...
<input type="file" name="foo" />
...
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript" src="https://raw.github.com/javanto/jquery-fileinput/3.1.0/dist/jquery.fileinput.min.js"></script>
<script type="text/javascript">
//<![CDATA[
$().ready(function() {
$("input[type=file]").fileinput("<button>Browse...</button>");
});
//]]>
</script>
...
<input type="file" name="foo" />
...
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript" src="https://raw.github.com/javanto/jquery-fileinput/3.1.0/dist/jquery.fileinput.min.js"></script>
<script type="text/javascript">
//<![CDATA[
$().ready(function() {
$("input[type=file]").fileinput($("button").remove());
});
//]]>
</script>
...
<input type="file" name="foo" />
<button>Browse...</button>
- replacement Plain HTML, or a jQuery selector for the element intended to replace the file input.
With Opera (and Firefox versions before 4) we can't support the native CSS pseudo classes. Instead we'll provide them equivalent "pseudo pseudo classes" which are actually just normal CSS classes.
- .hover for :hover
- .focus for :focus
- .active for :active
At jsFiddle.
- jQuery
- 1.4+
- Chrome
- 24.0.1312.57 m
- Chromium
- 24.0.1312.56
- Firefox
- 18.0.2
- Internet Explorer
- 10.0.9200.16466
- Opera
- 12.14
- Safari
- 5.1.7 (7534.57.2)