-
Notifications
You must be signed in to change notification settings - Fork 759
Description
The Problem
CSS2 ::first-letter definition did explicitly allow float to be applied to ::first-letter pseudo-element:
These are the properties that apply to :first-letter pseudo-elements: …, float, …
This is also how browsers currently work: we can use float on the ::first-letter to emulate the initial-letter styles.
However, the most recent ::first-letter definition does not mention float, it is absent from the “Styling the First-Letter Pseudo-elements” section, only having the following escape hatch which could potentially allow the float:
any other properties defined to apply to ::first-letter by their respective specifications
But the most recent float definition does not mention ::first-letter in any way.
This creates an ambiguity in the specs, which can be problematic. For example, when creating bug reports for browser compatibility of this interaction, there is no place in spec other than CSS2 to mention.
Examples of issues:
-
How should
text-indentwork?text-indentspec says that it applies toblock containers.::first-letterspec mentions only css-text properties that apply to “inline elements”:any typesetting properties that apply to inline elements (see [CSS-TEXT-4])
- According to the definition of “block formatting context”, floats establish a new BFM:
Inline formatting contexts exist within (are part of their containing) block formatting contexts; for example, line boxes belonging to the inline formatting context interact with floats belonging to the block formatting context.
Now, should a) the
text-indentbe applied to the::first-letterwith afloat, b) if so, should we be able to override it?This being not defined in specs leads to browsers interpreting this differently:
- Firefox does not make the
::first-letterinherit thetext-indent, and does not allow overriding it. - Safari makes the
::first-letterinherit thetext-indentwhen it is floated, and it allows setting thetext-indenton it, making it possible to “reset” it. - Chrome also makes
::first-letterinherit it, but it does not allow overriding it, leading to an impossibility to use a floated::first-letterin a context withtext-indent.
-
Should the
shape-outsidework?As it can be only applied to the floated elements, and css-shapes does not mention
::first-letterit is uncertain how it should behave. Browser testing shows that Safari and Firefox allow applying it to the floated::first-letter, while Chrome does not apply it. -
How should browser built-in features like search or text selection work?
When the
::first-letterdoes not have afloaton it, things work well in all browsers.When we add
floatto the mix, weird things start to appear:- Chrome removes a floated
::first-letterfrom the page search, but allows selecting the letter. - Safari allows the floated
::first-letterto participate in page search, but is weird when selecting it (selection not visible, but the letter itself can be selected and copied). - Firefox is mostly ok: both page search works, and selection is nice, with the exception of when you try to select the word with the floated letter with a double click, it also selected the preceding newlines for some reason.
- Chrome removes a floated
Here is my CodePen demonstrating some of those issues (without shape-outside case): https://codepen.io/kizu/pen/NWOBNXM
There are other issues I saw in my testing, but I think this should be enough for the start.
Related issue: initial-letter
In the CodePen above there is also an initial-letter added to the mix, which often behaves very similarly to when the ::first-letter is floated (but not exactly).
Maybe it would be worth it to create a separate issue for it, but I think there is a lot in common in how we would want the initial-letter to behave which are similar to float, so I think it is worth mentioning it, as well as testing the float alongside it, as maybe this interaction should also be defined — I saw differences in how the letter is positioned between Chrome's initial-letter and Safari's -webkit-initial-letter implementations, for example.
There is a section “Interaction with floats”, but it only talks about how the initial-letter should interact with floats around it, not when they are combined.
Browser bugs
Initially I wanted to go and submit a bunch of browser bugs related to my findings, but given this is an undefined place in the specs, it would be complicated for the browser engines to “fix” them, as there is nothing to reference as “how it should be”. I hope this issue would lead to some clarifications that could be used to submit those bugs.