[Bug 15100] Right-aligning a numeric table column is much more work than it should be

https://www.w3.org/Bugs/Public/show_bug.cgi?id=15100

--- Comment #18 from Brian Lalonde <brian@webcoder.info> 2012-01-31 05:48:21 UTC ---
(In reply to comment #17)
> Show me a site where this is a real problem. Unless there's a compelling case
> to be made that this problem exists a lot, we shouldn't address it.

I couldn't find a single production site using the td + td + ... approach!
Everyone is decorating each cell. There must be a reason for this.

Here's a few I found quickly:

Wikipedia suggests align="right" or embedding a two-cell table in each numeric
cell for the integer part and the fractional part of the number!
http://en.wikipedia.org/wiki/Help:Table#Decimal_point_alignment
http://en.wikipedia.org/wiki/Usage_share_of_web_browsers (align="right")

Compass: "Experience cleaner markup without presentational classes."
http://compass-style.org/examples/compass/tables/all/
td class='numeric'

Google Analytics is right-aligning the entire table, then left-aligning text
columns
http://www.google.com/analytics/
table class="Yb" (.Yb td aligned right, td.so aligned left)

Yahoo! Finance
http://finance.yahoo.com/
td id="yui_3_3_0_2_1327965860085641" (styling individual IDs!)

CNN Money
http://money.cnn.com/data/markets/
td class="wsod_aRight"

Amazon.com Order history
td align="right"

BankOfAmerica.com transactions
td class="trans-balance-cell TL_NPI_Amt"

Woot! account history qty
td align="right"

NumericaCU.org transactions
td align="RIGHT"

StackOverflow.com reputation page (leftmost column)
td class="rep-cell"

What does your bank use?

> The "numeric semantics" are already present in the page, by virtue of the data
> being numeric. That's machine-detectable.

Loop through each cell in the table to determine which columns are numeric? 
That seems a pretty inefficient methodology!

> I don't see "keeping the CSS in perfect sync with the markup" as being a
> problem. If you really find this difficult you can just put the CSS in a scoped
> <style> block before the table.

This was discussed some time ago in StackOverflow, where the td + td + ...
approach didn't gain much traction:
http://stackoverflow.com/questions/1332406/better-way-to-right-align-text-in-html-table
IE6 was at least part of the reason then, I think. But it was described as
hackish.
Even if you nail down the first td with :first-child so the selector doesn't
"slide", the moment you change a column of td into th, or reposition the
columns, you (your toolset) must remember to update the CSS, where possible.
Even when scoped CSS is supported by browsers, I suspect it'll be disallowed to
users on most sites out of security or branding concerns.

Positional CSS selectors seem to violate the DRY principal. What happens when
you've defined this behavior in a single CSS file across multiple tables and
pages, then want to change one or more tables?

> They don't need to manage it, they just need to know the classes that site has
> available.

That's assuming the site has created such a class, and wants to support it.

> In practice, what you
> really want is decimal alignment, precise control over padding, etc.

No, I think just decimal alignment. Something like <col align=char>, but
functional, and semantically attached to the data rather than maintained
elsewhere.

> In non-CSS environments, UAs can already automatically style numeric cells, so
> it doesn't help them.

I'm not familiar with this. Examples?

> The backwards-compatibility story here is terrible (it wouldn't work in any
> existing browser, and would cause serious difficulties due to the changes it
> requires in the parser).

Agreed. Adding an element, especially one that ruins backward compatibility
should be avoided.

However, there seems to be a widespread need for this functionality.

> Plus, it would be insufficient. What if the content isn't numeric but is of the
> form "foo - bar" and you want to align on the hyphen, say?

That seems to be a strawman. How often does this come up, compared to numeric
data? Examples?

> I meant that I haven't seen people marking up their tables to indicate which
> bits are numeric, which bits are dates, etc. Sure, people use align="", but
> they can use CSS just as easily in the vast majority of cases (more easily,
> even).

Numbers have very specific expectations, dates and other types don't.

If you have widespread examples of numeric data tables that don't decorate each
cell, then I'm likely in error.
Otherwise, the evidence I've provided would seem to suggest that there's an
itch out there.

-- 
Configure bugmail: https://www.w3.org/Bugs/Public/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.

Received on Tuesday, 31 January 2012 05:48:29 UTC