Created
August 29, 2014 09:21
-
-
Save zanonnicola/4fb5ba3cf5de8b6f9bd9 to your computer and use it in GitHub Desktop.
Change Font-Size within Input Field Based on Length W<input type="text" id="location" placeholder="Placeholder Text" />hat should happen when text within input fields are excessively long. The desired result we both agreed on was to change the font size on the fly. Thankfully this is extremely easy with a little bit of jQuery that listens to eve…
This file contains 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
<style> | |
#location { | |
font-size: 100%; | |
outline: none; | |
width: 200px; | |
height: 30px; | |
display: table-cell; | |
vertical-align: middle; | |
border: 1px solid #ccc; | |
} | |
</style> | |
<input type="text" id="location" placeholder="Placeholder Text" /> | |
<script> | |
$('#location').keypress(function() { | |
var textLength = $(this).val().length; | |
if(textLength < 20) { | |
// Do noting | |
} else if (textLength < 40) { | |
$(this).css('font-size', '85%'); | |
} else if (textLength > 40) { | |
$(this).css('font-size', '70%'); | |
} | |
//console.log(textLength); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment