admin管理员组文章数量:1277898
I have a input (html element) and sometimes the input (text) from the user is larger then the width of the input (html element) is there a way to make the input (html element) auto grow when the user is typing?
Obs. Better if made only with css
-------------------------------------EDIT 1-----------------------------------
I've made a JSfiddle, and as you can see the text is cropped when you enter to much text. I'm now trying to make it work with <span contenteditable="true" >
I have a input (html element) and sometimes the input (text) from the user is larger then the width of the input (html element) is there a way to make the input (html element) auto grow when the user is typing?
Obs. Better if made only with css
-------------------------------------EDIT 1-----------------------------------
I've made a JSfiddle, and as you can see the text is cropped when you enter to much text. I'm now trying to make it work with <span contenteditable="true" >
- stackoverflow./questions/7168727/… – Pawan Commented Aug 31, 2016 at 13:33
4 Answers
Reset to default 6If you need a no javascript/jquery solution I would remend you to use contenteditable
div instead of input element
Here's an example https://jsfiddle/sohelansari/631uzco9
Or if you want to use input element only, then unfortunately a pure css solution is not possible. You can write a jquery plugin, may be something like this -> Is there a jQuery autogrow plugin for text fields?.
<span contenteditable="true" style="display: inline-block; border: solid 1px black; min-width: 50px; max-width: 200px"></span>
Try adding oninput="this.size = this.value.length"
to your input tag.
<input
type="text"
oninput="this.size = this.value.length"
/>
function copy_data(val){
var a = document.getElementById(val.id).value
document.getElementById("text_to").value=a
}
</script>
</head>
<TEXTAREA ID="text_from" style="height:100px; width:600px;">
</TEXTAREA>
<TEXTAREA ID="text_to" style="height:100px; width:600px;">
</TEXTAREA>
<button onclick=copy_data(text_from)>Copy</button>
本文标签:
版权声明:本文标题:javascript - how to make a html input expand when the text inside is larger then the input itself - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741288810a2370425.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论