-
Notifications
You must be signed in to change notification settings - Fork 711
[css-values] Proposal: sp
and rsp
space glyph units
#10534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Especially but not only within justified alignment, the actual width of inter-word spaces is flexible. That seems to make |
@Crissov Good to know, how is the width calculated? Is the U+0020 character fully flexible in each instance or do browsers sometimes choose different space characters? |
I don't think justification would be relevant here; an Whether a new unit is actually useful enough to justify its existence is unclear to me... in most cases, it seems like
might be better addressed by allowing |
Regarding
I'd be pretty hesitant to start down this road. We'd have to either decide what fallback value to use if the requested character isn't supported by the first available font (and if we're using fallbacks, the point of measuring specific characters may be largely defeated), or else deal with the issue that every character might resolve to a different font resource, depending on character coverage/unicode-range usage. Yes, the browser already has to deal with this when rendering text, but I don't think all that complexity should be pushed down into the definition of a CSS unit. (We already have to deal with this for two specific characters to support the |
Related issue with some earlier discussion: #3232. |
A potential problem here is that the CSS text is only referencing abstract characters, not specific glyphs (there is no way to directly reference specific glyphs in CSS, you only access them indirectly through combinations of characters, fonts, font features, etc). While in many cases it is a simple relationship where only 1 glyph represents 1 character, that is definitely not always true. But if you did make a space unit for any arbitrary character based on the current font and text shaping situation (as with the |
@jfkthame Thanks for the previous discussion reference. Percentage-based The Personally I only use JS as a last resort when it comes to layout, as it can be fragile, so I just use an approximate |
@nicksherman That certainly would make things more difficult. Does
That's the slippery slope I thought might happen. The |
I'm not sure this would address your use case as you intended, since units compute to an absolute length before inheriting. So for example, if I set I think your codepen shows some reasonable use cases though, so it's worth thinking about how to make this kind of thing work... |
Background
There is currently no reliable way of knowing the advance measure of a space glyph. It can be estimated using
ch
unit, however this is not very precise and will change depending on whichever font from the stack is being rendered. Ansp
unit would improve ergonomics and could potentially open up new design possibilities, as outlined in the "Use Cases" section. Given that glyph metric units already exist (ex
,ch
), perhaps some of the technical details for this proposal have already been implemented.Proposal
Add
sp
andrsp
units which represent the advance measure of the space (U+0020) glyph. It may be desirable to follow the same logic as thech
unit spec, including fallbacks where it is impossible or impractical to determine the measure of the space glyph.Use Cases
word-spacing: 1sp;
word-spacing: -1sp;
letter-spacing: 3sp;
gap: 1sp;
Initial exploration of these uses can be found on Codepen.
Questions & Concerns
margin: am('M'); /* advance measure of the "M" glyph */
margin: am(' '); /* advance measure of the space glyph */
inline-size: max(am('W'), am('o'), am('r'), am('d')); /* faux-monospace using the largest advance measure from a list of glyphs */
The text was updated successfully, but these errors were encountered: