W3C home > Mailing lists > Public > www-style@w3.org > January 2012

Re: text-oveflow for _multiline_ texts

From: Brad Kemper <brad.kemper@gmail.com>
Date: Sun, 15 Jan 2012 15:28:59 -0800
Message-Id: <9700794B-E481-4F2F-B2C0-980AF8B6427E@gmail.com>
Cc: "www-style@w3.org" <www-style@w3.org>
To: "Marat Tanalin | tanalin.com" <mtanalin@yandex.ru>
On Jan 15, 2012, at 11:49 AM, Marat Tanalin | tanalin.com <mtanalin@yandex.ru> wrote:

> 15.01.2012, 22:54, "Brad Kemper" <brad.kemper@gmail.com>:
>> On Jan 15, 2012, at 6:54 AM, Marat Tanalin | tanalin.com <mtanalin@yandex.ru> wrote:
>>>  Hello. It would be nice to be able to use text-overflow property for _multiline_ (and _multiword_) texts sothat _last_ visible line of text would be clipped same way as it currently happens with single-line texts.
>>>  This could be done by specifying maximum number of _lines_ to display (in addition to text-overflow type like 'ellipsis') _without_ making text unwrappable with {white-space: nowrap}:
>>>  Possible syntax:
>>>     /* 'ln' unit means 'line' */
>>>     DIV {text-overflow: 3ln ellipsis; }
>>>  This could be splitted/expanded to following subproperties:
>>>     DIV {
>>>         text-overflow-limit: 3ln;
>>>         text-overflow-style: ellipsis;
>>>     }
>> It seems odd to me to have the text clipping done by something other than an edge of the content box. If you have a measure for number of lines (3ln, above), then why not use that for box height (height: 3ln;)? Then you could have something like 'text-overflow-lines: single | multi', and use it in a shorthand that defaults to 'single'. A new unit based on the height of line-boxes is not strictly necessary for this, and is really a separate issue. Until then, this would suffice to accomplish your main goal, I think:
>> DIV {
>>    line-height: 1.5em;
>>    height: 4.5em;
>>    overflow: clip;
>>    text-overflow: ellipsis multi;
>> }
> Thanks for the comment, Brad.
> Need for calculating height/line-height ratio is redundant and harmful since we could then be forced to change height each time we change line-height. Also, browser's rounding accuracies could result in wrong/inconsistent rendering.

I meant that is just how the general mechanism could work, simply, without relying on a height value within text-overflow. I do think a 'ln' unit would be helpful, but then it could just be used with 'height', 'max-height', or 'min-height', with less rewriting and rethinking of the rules for how those are resolved.

Multi-line text overflow seems useful, and so does a height based on number of line boxes. I just don't think they have to be tied together so tightly.  

> Even worse, real line height is not always equal to specified one -- for example, if text has inline image which height is greater than specified line-height.
> Moreover, required height of a block is not always equal to total height of text lines we want to display. It would be unreasonable to force web-developers to add extra-wrapper if we could do the same without extra-wrapper and with more smart CSS feature.

I don't see why it would require an extra wrapper. Can you give an example?

> So instead, we could just set number of lines, and browser could do the rest for us. Such automation is quite reasonable and handy.

Sure. I'm just setting it in a more reasonable place, and not tying that measurement unit to one particular property.  

>> A new unit based on the height of line-boxes is not strictly necessary for this, and is really a separate issue.
> New unit just gives us some flexibility as for adding another type of limit in future. For example, if we'll want to clip by number of characters, we could use 'ch' unit:
>    DIV {text-overflow: 10ch ellipsis; }
> This would mean that not more than 10 characters should be shown (this would make sense at least for monospace fonts).

Meh. You could just set the width to 10ch for much the same effect. Maybe use something like an :inner pseudo-element set to that instead, if you want to maintain a border further out.

> In abstraction from such flexibility, we could have just dedicated text-overflow subproperty such as text-overflow-lines without need for new unit at all:
>    DIV {
>        text-overflow-lines: 3;
>        text-overflow-style: ellipsis;
>    }

And what if I want to have multi-line overflow, but based on pixels instead of lines? Do we also add a 'text-overflow-px' property? This doesn't seem better.

> Exact way to specify number of lines is subject to discuss. The main point is much more fundamental: add ability to clip text by number of lines to be able to use text-overflow with multiline texts which is (AFAIK) currently impossible

Mostly agree, but it looks like two problems to me: being able to set a measurement based on number of lines, and being able to have an ellipsis on the last line of a multi-line text that has been clipped. We already have ways to clip and to set heights.

> thus making text-overflow almost useless in real practice.

I wouldn't go that far. A lot of people still find it pretty useful.
Received on Sunday, 15 January 2012 23:29:59 UTC

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