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 8417977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:11:28+00:00 2026-06-10T02:11:28+00:00

I have aligned textboxes with their labels using the line-height method proposed here .

  • 0

I have aligned textboxes with their labels using the line-height method proposed here. I didn’t simply use the width attribute because I wanted it to dynamically adjust if the label text changed. To get Firefox (haven’t tried other browsers) to apply the line height to the column with the inputs, I had to use this hack (note the <div class="hack">):

HTML

    <div class="textbox-column label">
        <div>User Name:</div>
        <div>Password:</div>
    </div>
    <div class="textbox-column input">
        <div><div class="hack">#</div><input type="textbox" name="username" /></div>
        <div><div class="hack">#</div><input type="password" name="password" /></div>
    </div>
    <div class="clear"></div>

CSS

div.clear {
    clear:  both;
}

.textbox-column {
    line-height:1.6em;
}
.textbox-column.label {
    float:  left;
    margin-right:1em;
}
.textbox-column.input {
    float:  right;
}
.textbox-column .hack {
    display: inline;
    width: 1em;
    margin-right: -1em;
}

Can any one suggest a cleaner solution?

Here is a live demo of this code: http://jsfiddle.net/fbe7P/

  • 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-10T02:11:30+00:00Added an answer on June 10, 2026 at 2:11 am

    CSS works best when things are grouped together, so I would group the controls into rows.

    Also, the plus side of this method is that it degrades well for small screen sizes.

    HTML:

    <div class="row">
        <label for="username">Username:</label>
        <input type="text" id="username" />
    </div>
    
    <div class="row">
        <label for="password">Password:</label>
        <input type="password" id="password" />
    </div>​
    

    CSS:

    .row {
        overflow: auto;
    }
    
    .row label {
        float: left;
        min-width: 100px;
    }
    
    .row input {
        float: right;
    }
    

    Demo: http://jsfiddle.net/ezp9H/2/

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

Sidebar

Related Questions

I have two text files in two different languages and they are aligned line
I am using the BoxLayout layout manager in java, and have aligned a bunch
I have: axis-aligned rectangle R ; non-vertical line A (specified by two points); vertical
I have an ImageView aligned to the parent right in a relativeLayout. Here is
In my App I have 7 buttons aligned using relative layout. The order I
I want to have 3 aligned parallel to each other. I have seen few
How to automatically format PhpDoc comments in Netbeans? I'd like to have comments aligned
I want to have 3 divs aligned inside a container div, something like this:
I know that IE is impossible sometime. I have 6 divs aligned to the
I have recently coded my button to be aligned to the right of the

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.