W3C home > Mailing lists > Public > www-style@w3.org > July 2013

Re: [css-text] text-align-last and cascading

From: Bert Bos <bert@w3.org>
Date: Wed, 31 Jul 2013 17:00:04 +0200
To: www-style@w3.org
Message-Id: <201307311700.04678.bert@w3.org>
On Friday 14 June 2013 11:56:18 fantasai wrote:
> There was an open issue on whether 'text-align-last' has an effect
> when 'text-align: justify' or not. IIRC in IE, it only works when
> 'text-align: justify', whereas in Gecko it works any time.
> Thinking about this, I noticed we have this problem:
>    p {
>      text-align: justify;
>      text-align-last: justify;
>    }
>    p.special {
>      text-align: center;
>      /* last line will be justified!? */
>    }
> Having the two properties be independent creates this cascading
> problem. IE dealt with it by only triggering on 'text-align:
> justify'.
> An alternate way to deal with it is by making 'text-align' a
> shorthand of 'text-align-last'. This has a few benefits:
>    1. Solves cascading problem 100%, even for more complex
>       cases that involve a return to 'text-align: justify'.
>    2. Allows nice shorthanding of common case with e.g.
>         text-align: justify-all;
>    3. Behaves the way authors would expect given 'text-align' is a
>       prefix of 'text-align-last'.
> There's one problem: backwards-compat. As long as existing documents
> predominantly use the order
>    text-align: justify;
>    text-align-last: <whatever>;
> they will continue to work. But if there are significant cases that
> use text-align-last: <whatever>;
>    text-align: justify;
> those will break.
> Full proposal would be:
>    text-align: <alignment-values>{1,2} | justify-all;
>    -> text-align-all: <alignment-values>;
>    -> text-align-last: auto | <alignment-values>;
>    (Alternatively, in this level, we could only allow a single
> position instead of two.)
>    The poetry use case that currently uses two values
>      text-align: start end; /* start-align first line, end-align rest
> */ would become
>      text-align: start-first end;
>    which is probably more understandable anyway. Or we could defer it
>    to L4 in case we want to consider a 'text-align-first' property
>    instead.
> Thoughts? Particularly from IE folks?

Maybe, in hindsight, 'text-align-last' as a separate property was a bad 
idea. Not just because of cascading, but also because it is difficult to 
explain: If there is only one line, you want it to be aligned as the 
last line, except in the poetry case, when it should be considered the 
first line.

I think I would like a single 'text-align' property with fifteen instead 
of four values, as follows:

1) First line left, subsequent lines right. If there is only one line, 
it is left: 'first-left' (B.t.w., how about a property 'line-break-
symbol: "[\A0"' to insert  "[ " before all lines except the first?)

2) First line right, subsequent lines left. If there is only one line, 
it is right: 'first-right'

3) All lines left: 'left'

4) All lines right: 'right'

5) All lines centered: 'center'

6) All lines justified and last line (or only line, if there is only 
one) left or right, depending on direction: 'justify'.

7) All lines justified and last line (or only line, if there is only 
one) left: 'justify-and-left'

8) All lines justified and last line (or only line, if there is only 
one) right: 'justify-and-right'

9) All lines justified and last line (or only line, if there is only 
one) centered: 'justify-and-center'

10) All lines justified: 'justify-all'

11) 'top-and-bottom' is an alias for 'left-and-right'

12) 'top' is an alias for 'left'

13) 'bottom' is an alias for 'right'

14) 'justify-and-top' is an alias for 'justify-and-left'

15) 'justify-and-bottom' is an alias for 'justify-and-right'

I don't think we need other combinations ('center-and-left', 'right-and-
center'...). The word "-and-" might also be "-then-", as in 'left-then-

If it is not possible to justify a line, that line is aligned on the 
same side as the last line. In the case of 'justify-all', it is aligned 
left or right depending on direction.

But 'text-align-last' was in a CR, can we still remove it?

Justification with spaces or kashida is an example of copyfitting. We 
need other forms of copyfitting as well: changing the font size, 
changing the font stretch and changing the line height (and later also: 
changing the content).

Maybe 'font-size' can get an extra keyword to indicate that the size may 
increase for the purposes of copyfitting. And likewise for 'line-
height'. 'Font-stretch' may be allowed to get more condensed. (If 
'height' is 'auto' and the text is not paginated, line height doesn't 
increase and font size is only used to justify; otherwise both font size 
and line height can increase to fill as much of the height as possible.)

The current definition of 'text-justify' defines a binary choice: there 
are expansion opportunities or there are not (depending on the content, 
the value of 'letter-spacing', and the value of 'text-justify' itself). 
The different opportunities on a line need not be stretched by the same 
amount, but together they must always fill the whole width.

However, you may want to expand up to a certain point: if text becomes 
stretched too much, it is better to give up and left-align it, for fear 
of it becoming unreadable. I.e., rather than

   d                                 e
   in Nederland zitten vol  met  lange

you'd want

   in Nederland zitten vol  met  lange

Authors may want to set the upper limit. E.g. XSL-FO allows to set 
minimum and maximum sizes on inter-word and inter-letter spaces. Or 
maybe it is a good enough if there *is* an upper limit and you can 
decide to apply it or not. E.g., you might have a limit that no text can 
become wider than twice its normal size.

To turn the limit off, 'text-justify' could have a keyword 'unlimited', 
which is like 'distribute' except that there is no limit on how much 
text can expand.

(This is one of the reasons I often put 'letter-spacing: 0' in my style 
sheets. But that doesn't stop inter-word spaces from expanding too much:

   de                                oude             
   arbeidsongeschiktheidsverzekeringen in
   Nederland   zitten   vol   met   lange

Another option is to use Media Queries and turn justification off 
altogether on narrow viewports, but that is a rather coarse method.)

You may want to guarantee that the last line of a paragraph is visibly 
shorter than the other lines. We could import the XSL-FO property 'last-
line-end-indent'. In the case the last line is justified, it gives the 
exact amount by which the last line is shorter, otherwise it gives the 
minimum amount. The value can even be negative...

  Bert Bos                                ( W 3 C ) http://www.w3.org/
  http://www.w3.org/people/bos                               W3C/ERCIM
  bert@w3.org                             2004 Rt des Lucioles / BP 93
  +33 (0)4 92 38 76 92            06902 Sophia Antipolis Cedex, France
Received on Wednesday, 31 July 2013 15:00:33 UTC

This archive was generated by hypermail 2.4.0 : Friday, 25 March 2022 10:08:32 UTC