Skip to content

[css-text] Replacement for text-align: <string> and solution for numeric column alignment #10791

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Crissov opened this issue Aug 27, 2024 · 0 comments

Comments

@Crissov
Copy link
Contributor

Crissov commented Aug 27, 2024

The CSS 2.0 value <string> for the text-align property has been removed from CSS 2.1 and been punted from CSS Text level 3 to level 4. XSL 1.1 keeps it.
Can I Use? data is not available yet, but has been requested. It has never been implemented in browsers as far as I know (except perhaps Presto-based Opera), but at least Antenna House Formatter does support it, while other PDF generators/print processors apparently don't (e.g. PrinceXML, Weasyprint, PDF Reactor, BFO Publisher).

  • <string>
    The string must be a single character; otherwise the declaration is invalid and must be ignored.
    When applied to a table cell, specifies the alignment character around which the cell’s contents will align.
    See below for further details and how this value combines with keywords.

HTML4 had the (optional) presentational attributes char and charoff for this in cell and column elements (if align=char was set), but the HTML LS omits it (also from alignment notes). I don't know if this was ever implemented anywhere.
It definitely is a desirable feature for ergonomics of tabular data, but it seems to be difficult or expensive to implement, so has been gotten shelved for over twenty years.

In #9877, I suggested that the string value could be dropped from text-align altogether if there was a CSS way to add leading and trailing invisible zeros to selectable contents (virtually U+2007 Figure Space and U+2008 Punctuation Space as needed). I doubt this could be done with td::after {content: …} like leaders.

While the current design is basically unimplemented and maybe insufficient, I cannot offer a proposal for a better solution to this problem yet. I think alignment templates as used in spreadsheet applications or cell content type hints could help, but I'm not even sure whether they belonged into HTML or CSS. I actually tend to prefer the former, although a dedicated element type might be better still. But even if the markup included information on the content that helped with its alignment, style authors would likely want to fine-tune or override it, so a CSS solution remains inevitable. A <string> longer than a single character could be interpreted as a spreadsheet-like number formatting pattern, e.g. #,##0.0??, and still remain backward-compatible with CSS2. (I'm not quite proposing that, though.)

A new value for the text-align property could help with the alignment of table cells. Called from-content, auto, numeric or tabular, it would horizontally align content like right if all applicable characters were numeric, whitespace or punctuation according to their Unicode properties, and like start (not left!) otherwise. (This would deal well with numbers in most notations, but lacked support for values that contain units.) OpenDocument uses text-align-source: fix | value-type where the latter keyword triggers the semi-automatic behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants