Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think using many textareas or input fields are the wrong way to go.</p> <p>Below you find an attempt to satisfy the indent, by adding spaces at the beginning if it doesn't exists. It also adds a &lt;ul&gt; element with many &lt;li&gt; elements to allow you to have line under the rows. It also scrolls the background if the textarea is filled with too much text. </p> <p>Tested in Chrome30, FF25 and IE10 and intended as a proof of concept. If you are going to implement this, you should probably dynamically add as many &lt;li&gt; elements as you need. And the events should be bound properly.</p> <p><a href="http://jsfiddle.net/some/VXNp2/" rel="nofollow">jsfiddle</a></p> <pre><code>&lt;!doctype html&gt; &lt;html&gt; &lt;head&gt; &lt;style&gt; div.mytext { position:relative; overflow:hidden; width:400px; height:200px; } div.mytext &gt; ul { position:absolute; top:5px; left:2px; font-weight:bold; color:#f00; list-style:none; width:100%; padding:0; margin:0; z-index:0; } div.mytext &gt;ul&gt; li { border-bottom:1px solid #000; width:100%; height:19px; } div.mytext &gt; ul, div.mytext &gt; textarea { font-size:12px; line-height:20px; font-family:courier; height:100%; width:100%; overflow:hidden; max-width:100%; max-height:100%; -moz-box-sizing: border-box; box-sizing: border-box; } div.mytext &gt; textarea { position:relative; background:transparent; } &lt;/style&gt; &lt;script&gt; function update(area) { if (!area.value.match(/^[ ]{8}/)) { area.value = ' ' + area.value.replace(/^\s+/,""); } if (area.selectionStart &lt; 8) { area.selectionStart = 8; } } function scroll(area) { area.parentElement.firstElementChild.scrollTop = area.scrollTop; } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div class='mytext'&gt; &lt;ul&gt; &lt;li&gt;Label:&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;/ul&gt; &lt;textarea onkeydown='update(this)' onscroll='scroll(this)'&gt;&lt;/textarea&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Explanation:</p> <ul> <li>Create a div that has position:relative to set a reference for the child elements position.</li> <li>Create a ul that has position:absolute, with as many li-elements as necesary. The label goes into the first one, and the others has a no-breaking-space to allow styling.</li> <li>When a key i pressed a function is called that tests with a regexp if the value of the textarea starts with a certain number of spaces, and adds them if they are missing.</li> <li>If the textarea is scrolled another function is called that will scroll the background too.</li> </ul> <p><strong>Disclaimer</strong>: This is only a proof of concept and needs more work if it is going to be used in production.</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. This table or related slice is empty.
    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