w3c / csswg-drafts

CSS Working Group Editor Drafts
https://drafts.csswg.org/
Other
4.5k stars 661 forks source link

[css-text] Propose 'text-indent: previous-line' or similar #1853

Open robinwhittleton opened 7 years ago

robinwhittleton commented 7 years ago

There’s a use-case for text-indent from traditional print layout that is not being met by the current specifications: a line indented to the end of the previous paragraph’s line. For example, this Keats poem:

The line beginning ‘Thus ended he’ is indented to the level of the end of the last line of the preceding paragraph ‘of weary life.’

or this poem from Wordsworth:

The line beginning ‘Though absent long’ is indented to the level of the end of the last line of the preceding paragraph ‘the hermit sits alone.’

text-indent: previous-line could work like this:

  1. Find the preceding generated line box in the DOM
  2. Measure its width
  3. Apply an indent in the natural language direction of the element the rule applies to that matches the width of the previous element.

Obviously as with anything like this there are a bunch of interactions that would need to be discussed:

As far as I can work out there’s nothing in any of the existing css-text specifications that would allow this. It’s not important enough for inclusion in CSS Text 3, but is it a valid use case for CSS Text 4?

I’ve not tried to suggest an extension to the specs before so I’m not sure this is the best way to go about it; if I should be making a proposal on a mailing list I’ll happily do that instead.

Loirooriol commented 7 years ago

I think this should be restricted to the previous line box inside the same block formatting context. Or maybe inside the same column box.

robinwhittleton commented 7 years ago

Incidentally it looks like this typographical arrangement might be called ‘dropline paragraphs’. An alternative value could be text-indent: dropline? That feels a little less readable to me though.

frivoal commented 7 years ago

I think this is commonly found in longform text in verse. Not the most common form of writing currently, but certainly one with lots of existing content.

I cannot comment about how browsers would prioritize this, but I'd support having it.

+1 to scoping it per BFC, but I don't see why it should be limited to a single column box. I don't think this really simplifies anything, and even if it ends up in a different column, it is still the later half of a verse.

Loirooriol commented 7 years ago

How should this behave in the presence of floats?

image

frivoal commented 7 years ago

@Loirooriol great question. I suspect we might actually be quite free to chose what we prefer here, because as far as I know the traditional use case is not used together with floats.

My personal expectation would probably be:

robinwhittleton commented 7 years ago

Agreed that whatever is easiest for browser manufacturers to implement, the simplest algorithm, is probably the preferred option here. In that case, I’d vote for column 2 in every case I think.

patrickdark commented 7 years ago

@Loirooriol I'd say the rule should be to always horizontally align text which should lead to a result of left/right/left/left.

Aligning to the last line would also be fine, which would lead to a result of left/left/left/left.

Simply measuring the preceding text width only and matching that seems to defeat the point of the feature if it results in a misalignment.