Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This works for me (Firefox 3.6/4.0 and Chrome 10/11):</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>var observe; if (window.attachEvent) { observe = function (element, event, handler) { element.attachEvent('on'+event, handler); }; } else { observe = function (element, event, handler) { element.addEventListener(event, handler, false); }; } function init () { var text = document.getElementById('text'); function resize () { text.style.height = 'auto'; text.style.height = text.scrollHeight+'px'; } /* 0-timeout to get the already changed text */ function delayedResize () { window.setTimeout(resize, 0); } observe(text, 'change', resize); observe(text, 'cut', delayedResize); observe(text, 'paste', delayedResize); observe(text, 'drop', delayedResize); observe(text, 'keydown', delayedResize); text.focus(); text.select(); resize(); }</code></pre> <pre class="snippet-code-css lang-css prettyprint-override"><code>textarea { border: 0 none white; overflow: hidden; padding: 0; outline: none; background-color: #D0D0D0; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;body onload="init();"&gt; &lt;textarea rows="1" style="height:1em;" id="text"&gt;&lt;/textarea&gt; &lt;/body&gt;</code></pre> </div> </div> </p> <p><em>If you want try it on <a href="http://jsfiddle.net/hmelenok/WM6Gq/">jsfiddle</a></em> It starts with a single line and grows only the exact amount necessary. It is ok for a single <code>textarea</code>, but I wanted to write something where I would have many many many such <code>textarea</code>s (about as much as one would normally have lines in a large text document). In that case it is really slow. (In Firefox it's insanely slow.) So I really would like an approach that uses pure CSS. This would be possible with <code>contenteditable</code>, but I want it to be plaintext-only.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload