Open Loirooriol opened 4 years ago
The CSS Working Group just discussed [css-lists] Should collapsible space after inside ::marker be preserved?
.
The CSS Working Group just discussed end
.
General consensus was that (2) was bad because it was hacky, (1) was probably bad both due to compat and because whitespace at the beginning of an element generally shouldn't have an effect, and (3) would actually be fine (notably, we didn't feel Oriol's concern was realistic, so no circularity would ever arise). We didn't have to literally specify that (3) was achieved thru pseudo-classes; rather we could just say that UAs could magically distinguish, but note that this is amenable to pseudo-classes should we ever wish to expose it to authors.
However, a better variant of (2) was presented after the close of the meeting, which is to specify ::marker { text-space-trim: discard-after; }
in the UA sheet, which would magically eat any collapsible whitespace after the marker and before the start of the element's content. This property isn't implemented anywhere yet, but it does exactly what we want and has wider use-cases as well, so it sounds like a pretty attractive option.
I like the idea in @tabatkins last comment if the property is actually implemented, so that it can be overridden by authors.
The upside of using an :inside and :outside pseudo class is that even if this is just conceptual, and actually implemented some other way, authors can still override that behavior by using a blunter selector.
The spec issue says
white-space: pre
doesn’t have quite the right behavior;text-space-collapse: preserve-spaces
+text-space-trim: discard-after
might be closer to what’s needed here.
But in https://bugzil.la/145075#c12 @MatsPalmgren argues that by default, a list item sized with min-content shouldn't have a line break between the marker and the first word of the list item.
So another proposal would be
text-space-collapse: preserve-spaces;
text-space-trim: discard-after;
text-wrap: nowrap;
In https://github.com/w3c/csswg-drafts/issues/4448#issuecomment-567144044 we resolved that ::marker should have
white-space: pre
in UA origin. That is needed for outside markers, and we decided to keep it simple and also apply it to inside markers.But consider this case:
For block container elements like
<li>
, leading and trailing space doesn't matter. So just looking at the HTML, some authors may think that bothText
will be aligned equally.However, the ::marker is inserted at the very beginning of the
<li>
, and since it's inside, it behaves as a normal inline. So the leading space is no longer at the beginning of the line, and is not trimmed in §4.1.2.1.Since the ::marker has a trailing space, both list items could still look the same via §4.1.1:
But that doesn't apply if the ::marker has
white-space: pre
. So the 1st list item ends up with 1 space and the 2nd list item with 2 spaces.What behavior do we want here? We don't have interoperability:
In Chromium (both legacy and LayoutNG), WebKit and old Edge, the texts are aligned:
In Firefox, they aren't:
So I guess we can choose among:
white-space: pre
. Firefox is correct, changing Chromium will be trivial.white-space: pre
but add some magic that if a text ::marker has a trailing space and is followed by collapsible spaces, then these collapsible spaces are removed, even if the ::marker space is not collapsible. This will keep Chromium's behavior but implementing this magic would be annoying.white-space: pre
in UA origin. This is close to what Chromium does right now. But I guess doing this properly would need pseudo-classes like::marker:inside
and::marker:outside
, even if just for internal use, but that would create a circularity if in the future we allow settinglist-style-position
in the ::marker itself.I lean towards 1.