A Pen by Captain Anonymous on CodePen.
Created
October 4, 2015 16:42
-
-
Save mofodox/f79bf65bb53ecde2ea0b to your computer and use it in GitHub Desktop.
KdWbWE
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
<textarea rows="1"></textarea> |
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
var textarea = document.querySelector('textarea'); | |
textarea.addEventListener('keydown', autosize); | |
function autosize(){ | |
var el = this; | |
setTimeout(function(){ | |
el.style.cssText = 'height:auto; padding:0'; | |
// for box-sizing other than "content-box" use: | |
// el.style.cssText = '-moz-box-sizing:content-box'; | |
el.style.cssText = 'height:' + el.scrollHeight + 'px'; | |
},0); | |
} |
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
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> |
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
textarea { | |
/*position: absolute;*/ | |
border: none; | |
/*min-width: 50%;*/ | |
font-size: 20px; | |
line-height: 28px; | |
padding: 25px; | |
width: 80%; | |
display: block; | |
margin-top: 15px; | |
margin-left: auto; | |
margin-right: auto; | |
resize: none; | |
overflow: hidden; | |
} | |
textarea:focus { | |
outline: none; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment