I can set initial text input size in css, like so:
width: 50px;
But I would like it to grow when I type until it reaches for example 200px. Can this be done in straight css, html, preferably without javascript?
Do post your js/jquery solutions too of course, but if this is doable without them - that be great.
my try here:
http://jsfiddle.net/jszjz/2/
To create a multi-line text input, use the HTML <textarea> tag. You can set the size of a text area using the cols and rows attributes. It is used within a form, to allow users to input text over multiple rows.
Use the span. text to fit width of text, and let the input have same size with it by position: absolute to the container.
Resize a text box Select the text box. Select one of the handles and drag until the text box is the size you want.
Here is an example with only CSS and Content Editable:
jsFiddle Example
CSS
span { border: solid 1px black; } div { max-width: 200px; }
HTML
<div> <span contenteditable="true">sdfsd</span> </div>
contenteditable
Making an HTML element contenteditable
lets users paste copied HTML elements inside of this element. This may not be ideal for your use case, so keep that in mind when choosing to use it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With