Last active
August 29, 2015 14:12
-
-
Save datafunk/c0a469762394a96b5a90 to your computer and use it in GitHub Desktop.
Custom format input type "file" and display the selected file. Problem asked on HTML5 mailing list, example makes use of SO thread as quoted in the code below.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>test</title> | |
<style type="text/css"> | |
label.myLabel input[type="file"] { | |
position: fixed; | |
top: -1000px; | |
} | |
/***** Example custom styling *****/ | |
.myLabel { | |
border: 2px solid #AAA; | |
border-radius: 4px; | |
padding: 2px 5px; | |
margin: 2px; | |
background: #DDD; | |
display: inline-block; | |
} | |
.myLabel:hover { | |
background: #CCC; | |
} | |
.myLabel:active { | |
background: #CCF; | |
} | |
.myLabel :invalid + span { | |
color: #A44; | |
} | |
.myLabel :valid + span { | |
color: #4A4; | |
} | |
</style> | |
</head> | |
<body> | |
<label class="myLabel"> | |
<input type="file" id="myInput" required /> | |
<span>fully custom label</span> | |
</label> | |
<!-- Above example is from http://stackoverflow.com/questions/21842274/cross-browser-custom-styling-for-file-upload-button --> | |
<div id="filename"> </div> | |
<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.3.min.js"></script> | |
<script type="text/javascript"> | |
var myInput = document.getElementById('myInput').value; | |
$('#myInput').change(function(){ | |
$('#filename')[0].textContent = $('#myInput').val(); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment