473,386 Members | 1,803 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

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
5 8311
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
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
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
<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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chung Jiho | last post by:
Hello, We have been deploying our web application over win2k servers. It is written in Python and uses Active Scripting to meet our requirements that it must be ASP application. So far, it was...
1
by: WU FUHENG | last post by:
Today,I found a strange problem in python multi-thread programming.When I used function win32com.client.Dispatch('ADODB.Connection') in primary thread, it was OK. But when I called it in...
0
by: Atul Kshirsagar | last post by:
I am embedding python in my C++ application. I am using Python *2.3.2* with a C++ extention DLL in multi-threaded environment. I am using SWIG-1.3.19 to generate C++ to Python interface. Now to...
0
by: frankenberry | last post by:
I have multi-page tiff files. I need to extract individual frames from the multi-page tiffs and save them as single-page tiffs. 95% of the time I receive multi-page tiffs containing 1 or more black...
2
by: Diz | last post by:
Can anyone please help with this? when i run the following query, using SELECT*, SELECT * FROM tbl_artwork, tbl_artworkmedium, tbl_medium WHERE tbl_artwork.artworkID =...
3
by: dice | last post by:
Hi, In order to use an external api call that requires a function pointer I am currently creating static wrappers to call my objects functions. I want to re-jig this so I only need 1 static...
0
by: pvannie | last post by:
Hello there, I've been trying to install DBD::mysql on Mac OS X Server 10.3 for 2 days, but it still raises error. So I'm going to send this message to ask for help. Any help will be much...
1
by: pvannie | last post by:
Hello there, I've been trying to install DBD::mysql on Mac OS X Server 10.3 for 2 days, but it still raises error. So I'm going to send this message to ask for help. Any help will be much...
19
by: 叮叮当当 | last post by:
hi, all when a email body consist with multipart/alternative, i must know when the boundary ends to parse it, but the email lib have not provide some function to indicate the boundary end,...
7
by: Adam01 | last post by:
Im not perl expert with perl, and I am trying to run a server script (that I didnt write). And perl reports: Can't locate IO/Compress/Gzip.pm in @INC (@INC contains:...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.