Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You're going to have to resolve yourself to using fixed widths for your labels (if going the pure CSS route.) Below is the minimum to get what you're trying to accomplish (pulled from <a href="http://htmldog.com/articles/formlayout/" rel="nofollow noreferrer">HTML Dog</a>.)</p> <p>CSS:</p> <pre><code>label { clear: left; float: left; width: 7em; /* or whatever length suits */ text-align: right; } </code></pre> <p>HTML:</p> <pre><code>&lt;form&gt; &lt;div&gt;&lt;label&gt;Item 1&lt;/label&gt;&lt;input /&gt;&lt;/div&gt; &lt;div&gt;&lt;label&gt;Item 2&lt;/label&gt;&lt;input /&gt;&lt;/div&gt; &lt;div&gt;&lt;label&gt;Item 3&lt;/label&gt;&lt;textarea&gt;&lt;/textarea&gt;&lt;/div&gt; &lt;/form&gt; </code></pre> <p>If you absolute don't want fixed widths, then you can use this javascript (with jQuery) and remove the fixed width from the above CSS. It is worth noting that if you get people with <em>javascript turned off, this will look awful</em>!</p> <pre><code>var largestWidth = 0; $('label').each( function() { if ($(this).width() &gt; largestWidth) { largestWidth = $(this).width(); } }); $('label').each( function() { $(this).width(largestWidth); }); </code></pre> <p>I've thrown up a live example on <a href="http://jsfiddle.net/fRBKE/" rel="nofollow noreferrer">JSFiddle</a>.</p> <p>Given the use case that you've cited, I actually think tables is the better way to go, but then I have a <a href="https://stackoverflow.com/questions/591539/forms-can-they-be-done-without-tables/591763#591763">differing opinion on the table/div form debate than most</a>.</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