Skip to content

Instantly share code, notes, and snippets.

@itsjavi
Last active October 13, 2015 05:57
Show Gist options
  • Select an option

  • Save itsjavi/4149425 to your computer and use it in GitHub Desktop.

Select an option

Save itsjavi/4149425 to your computer and use it in GitHub Desktop.
Twitter Bootstrap CSS style for file inputs
<!-- DEMO: http://jsfiddle.net/javieranid/Dpgba/1/ -->
<label class="btn btn-file btn-mini">
<input type="file" /> <span>Examinar</span>
</label>
<style>
.btn-file{
position:relative;
overflow: hidden;
}
.btn-file input[type=file]{
position: absolute;
z-index:1;
top:0;
left:0;
right:0;
bottom:0;
filter:alpha(opacity=0);
opacity:0;
cursor:pointer;
}
</style>
<script>
$(function(){
$('.btn-file input[type=file]').on('change', function(e){
var $btn = $(this).parent();
var basename = this.value.replace(/\\/g,"/").split("/").pop();
if(basename.length > 0){
var maxChars = 15;
$btn.addClass('btn-warning').find('span').html(basename.substr(0,maxChars-1) + (basename.length>maxChars?'...':''));
}
});
});
</script>​
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment