By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,002 Members | 2,137 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,002 IT Pros & Developers. It's quick & easy.

CSS problem: multi-column data form won't vertically align

P: n/a
I have a data entry web application that is formatted heavily
with tables. Having learned a bit of CSS, I'm hoping to rewrite
this using <div> tags. But I have run into a formatting problem
that keeps me from a solution. I'm hoping for some trick.

Assume that "label_a" is a <label> tag and "INPUT_A" is
an <input> tag. A sample of my current web page is:

<table>
<tr><td>label_a</td><td>INPUT_A</td>
<td>label_x</td><td></td></tr>
<tr><td>label_b</td><td>INPUT_B</td>
<td>label_y</td><td></td></tr>
<tr><td>label_c</td><td>INPUT_C</td>
<td>label_e</td><td>INPUT_E</td></tr>
<tr><td>label_d</td><td>INPUT_D</td>
<td>label_f</td><td>INPUT_F</td></tr>
</table>

rendered like this:

label_a INPUT_A label_x
label_b INPUT_B label_y
label_c INPUT_C label_e INPUT_E
label_d INPUT_D label_f INPUT_F

I use tabindex attributes to make the focus traverse A-B-C-D-E-F.

I want to rewrite this using <div> tags, as so:

<div>
<div style="float:left;">
<div>label_a INPUT_A</div>
<div>label_b INPUT_B</div>
<div>label_c INPUT_C</div>
<div>label_d INPUT_D</div>
</div>
<div style="float:right;">
<div>label_x</div>
<div>label_y</div>
<div>label_e INPUT_E</div>
<div>label_f INPUT_F</div>
</div>
</div>

If I write things this way I don't have to use tabindex at all!

But this doesn't quite give me the visual effect I want. It
turns out that the height of the <label> elements is less than
that of <input> or <select> elements, and so the right column
doesn't line up with the left column. The controls in the right
column are all about a third of a line higher up on the page.

label_a INPUT_A label_x & _y
label_b INPUT_B label_e INPUT_E
label_c INPUT_C label_f INPUT_F
label_d INPUT_D

("label_x & _y" is not the actual result, but is part of a
crude approximation to show that my initial <div> design yields
a display that doesn't look aligned *or* professional)

It turns out this is a general problem. If I structure things
with nested tables instead of nested divs:

<table>
<tr>
<td><table id="left">. A, B, C, D..</table></td>
<td><table id="right"> x, y, E, F..</table></td>
</tr>
</table>

then I get the same sort of problem. The height of table "left"
is different than that of table "right" and so the lines in the
"left" table don't line up with those of the "right" table.

I know I could bottom align both tables / divs, That would work
if the two columns were meant to align at the bottom and had
identical elements from the bottom. But I'm trying to solve the
more general problem.

So.....is there a nice solution that I haven't yet considered?
Thanks for help,
Jerome.

Jul 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On 3 Feb 2005 19:04:24 -0800, ja*****@sbcglobal.net wrote:
I have a data entry web application that is formatted heavily
with tables. Having learned a bit of CSS, I'm hoping to rewrite
this using <div> tags.


[...]

http://www.css.nu/articles/table-in-css.html

--
Rex

Jul 21 '05 #2

P: n/a
Jan Roland Eriksson wrote:
On 3 Feb 2005 19:04:24 -0800, ja*****@sbcglobal.net wrote:
I have a data entry web application that is formatted heavily
with tables. Having learned a bit of CSS, I'm hoping to rewrite
this using <div> tags.


[...]

http://www.css.nu/articles/table-in-css.html

--
Rex


Thanks for your reply. This site has examples of tables generated by
repeated use of div tags. The table is a div, each row is a div and
each cell (td) is a div. The cells also include paragraphs (<p>), but
perhaps that is overkill.

Anyways, because each row is included within a div the rows will always
line up. That is a straightforward replacement of <table>, <tr> and
<td> with <div>. But what it doesn't give me is freedom from tabindex.
Each embedded <input> will have to have a tabindex to control flow.
If I could generate the divs column first (the whole left column, then
the whole right column) and still have row alignment then I can get
what I was looking for in replacing a table with CSS.

I suppose another answer is to give each cell a too-large cell height
so that the rows line up. But I couldn't adapt to a user choosing a
very large font, for my too-large cell height might still be smaller
than the result of user font selection.

Jul 21 '05 #3

P: n/a
ja*****@sbcglobal.net wrote:
Jan Roland Eriksson wrote:
On 3 Feb 2005 19:04:24 -0800, ja*****@sbcglobal.net wrote:

I have a data entry web application that is formatted heavily
with tables. Having learned a bit of CSS, I'm hoping to rewrite
this using <div> tags.


[...]

http://www.css.nu/articles/table-in-css.html

--
Rex

Thanks for your reply. This site has examples of tables generated by
repeated use of div tags. The table is a div, each row is a div and
each cell (td) is a div. The cells also include paragraphs (<p>), but
perhaps that is overkill.

Anyways, because each row is included within a div the rows will always
line up. That is a straightforward replacement of <table>, <tr> and
<td> with <div>. But what it doesn't give me is freedom from tabindex.
Each embedded <input> will have to have a tabindex to control flow.
If I could generate the divs column first (the whole left column, then
the whole right column) and still have row alignment then I can get
what I was looking for in replacing a table with CSS.

I suppose another answer is to give each cell a too-large cell height
so that the rows line up. But I couldn't adapt to a user choosing a
very large font, for my too-large cell height might still be smaller
than the result of user font selection.

just made a collection of css tables, maybe you find something that fits
your needs.
http://homepage.hispeed.ch/zuzaniuk/test/csstable.html
Jul 21 '05 #4

P: n/a
<ja*****@sbcglobal.net>:
| label_a INPUT_A label_x
| label_b INPUT_B label_y
| label_c INPUT_C label_e INPUT_E
| label_d INPUT_D label_f INPUT_F
Anyways, because each row is included within a div the rows will always
line up. That is a straightforward replacement of <table>, <tr> and
<td> with <div>.
And a reason not to do it.
But what it doesn't give me is freedom from tabindex.
If I could generate the divs column first (the whole left column, then
the whole right column)
Sadly, CSS follows HTML's row-centric table model very closely.
and still have row alignment then I can get
what I was looking for in replacing a table with CSS.


In your case, doesn't setting 'line-height' (and perhaps 'height' and
'width') for 'label' and/or 'input' to a reasonable 'em' value help? At
least until there's a line break inside.

fieldset div {float: left; /*(max-)width: 50%;*/}
div label {display: block; width: 15em; line-height: 1.5em;}
label a {display: inline-block; width: 5em;}
/*for non-IE:*/
fieldset>div {display: table;} /*two floated CSS tables*/
div>label {display: table-row;}
label>a {display: table-cell;}
/*label>input{display: table-cell;} breaks Gecko: no input possible,
so let there be anonymous table-cells. */
/*MacIE + Safari?*/

<fieldset>
<div>
<label><a>a</a> <input type="text" name="A"></label>
<label><a>b</a> <input type="text" name="B"></label>
<label><a>c</a> <input type="text" name="C"></label>
<label><a>d</a> <input type="text" name="D"></label>
</div>
<div>
<label>x</label>
<label>y</label>
<label><a>e</a> <input type="text" name="E"></label>
<label><a>f</a> <input type="text" name="F"></label>
</div>
</fieldset>

Yes, the additional 'a' (or 'span' if you want) are very unfortunate.

--
The Hitchhiker's Guide to the Galaxy:
"The Universe, as has been observed before, is an unsettlingly big place,
a fact which for the sake of a quiet life most people tend to ignore."
Jul 21 '05 #5

P: n/a
Christoph Paeper wrote:
<ja*****@sbcglobal.net>:
| label_a INPUT_A label_x
| label_b INPUT_B label_y
| label_c INPUT_C label_e INPUT_E
| label_d INPUT_D label_f INPUT_F

Anyways, because each row is included within a div the rows will always line up. That is a straightforward replacement of <table>, <tr> and <td> with <div>.


And a reason not to do it.
But what it doesn't give me is freedom from tabindex.
If I could generate the divs column first (the whole left column, then the whole right column)


Sadly, CSS follows HTML's row-centric table model very closely.
and still have row alignment then I can get
what I was looking for in replacing a table with CSS.


In your case, doesn't setting 'line-height' (and perhaps 'height' and

'width') for 'label' and/or 'input' to a reasonable 'em' value help? At least until there's a line break inside.

fieldset div {float: left; /*(max-)width: 50%;*/}
div label {display: block; width: 15em; line-height: 1.5em;}
label a {display: inline-block; width: 5em;}
/*for non-IE:*/
fieldset>div {display: table;} /*two floated CSS tables*/
div>label {display: table-row;}
label>a {display: table-cell;}
/*label>input{display: table-cell;} breaks Gecko: no input possible, so let there be anonymous table-cells. */
/*MacIE + Safari?*/

<fieldset>
<div>
<label><a>a</a> <input type="text" name="A"></label>
<label><a>b</a> <input type="text" name="B"></label>
<label><a>c</a> <input type="text" name="C"></label>
<label><a>d</a> <input type="text" name="D"></label>
</div>
<div>
<label>x</label>
<label>y</label>
<label><a>e</a> <input type="text" name="E"></label>
<label><a>f</a> <input type="text" name="F"></label>
</div>
</fieldset>

Yes, the additional 'a' (or 'span' if you want) are very unfortunate.

--
The Hitchhiker's Guide to the Galaxy:
"The Universe, as has been observed before, is an unsettlingly big place, a fact which for the sake of a quiet life most people tend to

ignore."
What? You've placed the entire content of a "cell" into a <label>?
I'll have to learn more about that technique. In my case the "e" and
"f", etc., are just identifiers for the <input> field, so they won't
have any links in them. Is there a reason this couldn't be <label> e
<input /></label> ?

I *could* use a "reasonably large" line height, which works for
"reasonable" font selections. Not ideal, but...

Aside from that, I'm beginning to think that the structure of the data
input form is part of the document. That is, the data field are
important, but so is their spatial relationship (going down this
column, then the other column). If that philosophy is followed using a
<table> to enable/enforce the relationship isn't that bad an idea.
Comments?

(another way of saying it is redefining "victory" and then quitting)
Jerome.

Jul 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.