Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make html text input field grow as I type?

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/

like image 899
Stann Avatar asked Aug 23 '11 23:08

Stann


People also ask

How do I make my text field bigger in HTML?

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.

How do I make input width fit content?

Use the span. text to fit width of text, and let the input have same size with it by position: absolute to the container.

How do I resize a text field?

Resize a text box Select the text box. Select one of the handles and drag until the text box is the size you want.


1 Answers

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> 

Important note regarding 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.

like image 161
Joe Avatar answered Oct 04 '22 06:10

Joe