Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8731247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:11:31+00:00 2026-06-13T09:11:31+00:00

I’m building a bunch of forms that have labels and corresponding fields (input element

  • 0

I’m building a bunch of forms that have labels and corresponding fields (input element or more complex elements).

Labels go on the left, fields go on the right. Labels in a given form should all be a specific width so that the fields all line up vertically.

There are two ways (maybe more?) of achieving this:

  1. Rows: Float each label and each field left. Put each label and field in a field-row div/container. Set label width to some specific number. With this approach labels on different forms will have different widths, because they’ll depend on the width of the text in the longest label.

  2. Columns: Put all labels in one div/container that’s floated left, put all fields in another floated left container with padding-left set. This way the labels and even the label container don’t need to have their widths set, because the column layout and the padding-left will uniformly take care of vertically lining up all the fields.

So approach #2 seems to be easier to implement (because the widths don’t need to be set all the time), but I think it’s also less object oriented, because a label and a field that goes with that label are not grouped together, as they are in approach #1. Also, if building forms dynamically, approach #2 doesn’t work as well with functions like addRow(label, field), since it would have to know about the label and the field containers, instead of just creating/adding one field-row element.

Which approach do you think is better? Is there another, better approach than these two?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:11:33+00:00Added an answer on June 13, 2026 at 9:11 am

    Approach #1 is the far better for a number of reasons, mainly pertaining to flexibility and the other points mentioned by Kevin Boucher, plus your own points with regard to dynamic creation.

    I wouldn’t recommend not having containing elements – even though it is nicely possible – you deny yourself a lot of extra power with regards to padding, positioning and overflow handling. It also makes dynamic creation more tricky.

    Your arguments for going with approach #2 also need not be a benefit either, considering you can set one width for your label container in your css – via a class – and this can easily be changed or designed to be responsive. Basically meaning you only have one place again to change your label dimensions.

    Also With #2, whilst making your horizontal label layout more automatic – vertical layout would become more manual and tricky considering you would have to give your label and field containers the same height in order to line up (as they couldn’t rely on a mutal parent). I’d make a guess that you’ll have more rows than columns so this would just add work 😉

    css:

    .field-row {
      overflow: hidden;
    }
    
    .field-row label {
      display: block;
      width: 30%;
      float: left;
    }
    
    .field-row .field-container {
      width: 70%;
      float: left;
    }
    

    markup:

    <div class="field-row">
      <label>Label Text</label>
      <div class="field-container">
        <input type="text" />
      </div>
    </div>
    

    I’d probably go for the above myself as that would cover most of what I’ve ever needed, however if you wanted more control with regard to possible future changes that might occur in your app, you could do the following:

    css 2:

    .field-row {
      overflow: hidden;
    }
    
    .field-row .label-container {
      width: 30%;
      float: left;
    }
    
    .field-row .field-container {
      width: 70%;
      float: left;
    }
    

    markup 2:

    <div class="field-row">
      <div class="label-container"><label>Label Text</label></div>
      <div class="field-container">
        <input type="text" />
      </div>
    </div>
    

    By just adding one extra wrapper you then allow for the ability of more complicated labels (i.e. hiding the text and replacing with images, or adding explanatory text with js) – you also give yourself more control with regards to center or right alignment.

    Anyway just my thoughts 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small JavaScript validation script that validates inputs based on Regex. I
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.