tags:

views:

62

answers:

3

I cant figure it out. How do i align the textbox? I thought using float: left on the labels on the left (then doing it on the input when i notice the input was now on the left without that) but that was completely wrong.

How do i get the textbox align along with the labels on the left of them next to the textbox instead of the far left?

The picture is an example of what i'd like it to look like.

alt text

A: 

you can do a multi div layout like this

<div class="fieldcontainer">
    <div class="label"></div>
    <div class="field"></div>
</div>

where .fieldcontainer { clear: both; } .label { float: left; width: _ } .field { float: left; }

Or, I actually prefer tables for forms like this. This is very much tabular data and it comes out very clean. Both will work though.

Jeremy B.
+2  A: 

You have two boxes, left and right, for each label/input pair. Both boxes are in one row and have fixed width. Now, you just have to make label text float to the right with text-align: right;

Here's a simple example:

http://jsfiddle.net/qP46X/

Nikita Rybak
+1 for not going anywhere near `table`
Floyd Pink
Floyd that is an ignorant statement. Tables have specific places in which they work very well. CSS is not a solve all tool, and if you can't see past that, do not recommend poor solutions, you do people a disservice.
Jeremy B.
@Jeremy I have very limited experience with web design (month or so), but my personal sentiment is that tables should be avoided like a plague (for anything except, well, tables themselves). It's, of course, just a subjective opinion, but I've had too many problems with them over the course of that month.
Nikita Rybak
A: 

Using a table would be one (and easy) option.

Other options are all about setting fixed width on the and making it text-aligned to the right:

label {
   width: 200px;
   display: inline-block;
   text-align: right;
}

or, as was pointed out, make them all float instead of inline.

Sergey