-
Notifications
You must be signed in to change notification settings - Fork 719
[css-text] Allow letter-spacing to have unitless values like line-height #2165
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
Hi @benface, this seems like one of the problems that CSS Variables were designed to solve for us—passing down values from a parent to its children! I'd rather embrace a solution that uses CSS features available today (using CSS Variables to their fullest) rather than expanding CSS to include new units to accomplish something that's already possible. In this particular case of "passing down a value from a parent to its children" you want a new unit to set So, phrased another way: How many new units would you need to add to CSS if we want to avoid using CSS Variables cases where we want to pass a value down to children? |
Makes sense @tomhodgins, but I would add two things:
|
Note: unitless values are a new unit - they're just a lazier way of adding a new unit without actually minting a new suffix. I'm trying to avoid adding new ones in new designs, when possible - when plain numbers are actually lengths in disguise, it makes calc() dramatically more complicated. (See the third note in https://drafts.csswg.org/css-values/#calc-syntax where we talk about how it's not actually allowed - you can't add together |
I was thinking about this problem just the other day, and was surprised this wasn't a solved problem already. Totally agree with the premise. @tabatkins We could use percents here. It's inconsistent with how An interesting question is whether the ratio should be relative to So the proposal is that Then there's the question of what |
BTW. Why word-spacing:0px still make a gap between words? Is there solution to set no spacing between words and between inline-blocks without removing CR LF from code? |
@fantasai, I believe that calculating percentage from the width of the normal inter-word space is useful (one quite common use case would be removing spaces completely with And what about reusing the @Nadya678, the |
I thing the BTW. The flex-box has side effects and It cannot be used in part of layouts. Also hacks has side efects like losing of antialiasing on iOS browsers (font-size:0).
Yes - for part of standard fonts it is very appreciated.
How will it work? How to use the pseudo-unit for spacing? |
The Working Group just discussed
The full IRC log of that discussion |
The CSS Working Group just discussed
The full IRC log of that discussion |
Using % to do this sounds a bit weird to my front-developer ear. Maybe just because it's new. Maybe because there is something weird about it. When I feel this way, I like to bounce things off other FEDs, to see what they think. So I wrote a poll on Twitter during the F2F, just to see what happens / to see if there's universal outcry of yuk, or how people react... https://twitter.com/jensimmons/status/1054309608574148610 |
FWIW I think letter-spacing is today better dealt with as a font-variations-settings axis, rather than as a text/typesetting layout engine property :) |
But not all fonts will support that. |
Also, in the twitter thread Jen instigated, I suggested "per mille of em" and have this follow up from DB
|
I will quote my tweet here ( “I proposed that CSS should honor a long-standing typographic tradition, in which: Tracking of 17 → 17 thousandths of an em. All professional software does it correctly. It’s like telling astronomers they must define apparent magnitude in lux. It shouldn’t be up for debate.” |
@decivilizator We try to avoid unitless numbers that ultimately resolve to lengths, it creates problems in The advantage of using percents over a custom unit here is that they are a type of value that already exists, and get preserved distinctly from lengths during inheritance (which is the behavior we need here). But introducing a new unit such as upm is a valid alternative. |
Fixed for text-decor-4, still needs edits for css-text-4 (but that's pending merge of css-text-3 into css-text-4). |
@fantasai I think it's bad that this behaves differently from Percentages usually resolve "as soon as possible", this breaks that rule by intentionally inheriting them like percentages rather than the resolved length. |
(Or otherwise this doesn't fix the bug, right?) |
To be clear, >
<style>
div {
line-height: 100%;
font-size: 16px;
}
span {
font-size: 32px;
}
style>
<div><span>span>div>
<pre>
<script>
document.write(getComputedStyle(document.querySelector("span")).lineHeight);
script>
pre> Shows |
Not sure how I feel about this... the inconsistency is regrettable, but the proposed behavior here (inheriting as a percentage and resolving "late") is more useful than computing to a The behavior of |
But are there properties where a percentage value is inherited as a percentage? I can't think of any. |
I think that's how |
All layout-relative percentages are inherited as percentages. The problem is that I'm not sure any of them inherit by default, so you'd only see the effect if you were explicitly using the This is probably close to a category feature: the only reason to resolve post-computed value is if you depend on layout, or have a special reason to want your resolution-reference to change as you inherit; (almost?) all of the former are non-inherited layout-related properties, while the latter is rare (like |
Yes, sorry, I meant for inherited properties. I could only think of |
Looking back, I see that @fantasai explicitly mentioned the inconsistency with Personally, I agree with the assessment that " |
I think it's still a bit weird that it's inconsistent with both |
Should this be accepted, I would hope word-spacing would be treated in similar fashion. |
The Working Draft "CSS Inline Layout Module Level 3" mentons:
I think this applies to all non-unitless values for To fix this behavoir, i would love a property like |
Finally got around to merging CSS-TEXT-3 into CSS-TEXT-4. :/ Edits for this issue are now also in, so closing out. |
I just wrote a kind of follow-up to this issue, for those who are interested: #9612 |
Uh oh!
There was an error while loading. Please reload this page.
Problem
There is often a need to set the letter spacing of an element to a fraction of its font size to reproduce a given design, and have it propagate down as it should (like most text-related properties,
letter-spacing
is inherited). That can be done with anem
value, but unfortunately it breaks when the font size changes in a descendant element, because the value is computed using thefont-size
that is used where theletter-spacing
is set.Example:
(JSBin here: https://jsbin.com/gupekikena/edit?html,css,output)
In this example, we want the letter spacing to be 0.1 times the font size. This is the equivalent of setting the "tracking" in Photoshop to 100 since "Tracking and kerning are both measured in 1/1000 em" (source: https://helpx.adobe.com/photoshop/using/line-character-spacing.html). However, that value is computed directly in
.rich-text
and becomes a fixed1.6px
, so in anh1
, even though we set thefont-size
to32px
, the letter spacing is still1.6px
and not3.2px
like we'd expect. We have to duplicate theletter-spacing: 0.1em;
rule every time we change the font size in a descendant to have the result we want.Proposed solution
Introduce a new unitless value option for
letter-spacing
that works likeline-height
's unitless values. Notice in the example above, the line height is set to 1.5 times the font size, and it properly propagates down toh1
and any other descendant that changes the font size. I believe a unitless value forletter-spacing
should work exactly like that. We would simply have to remove theem
in the example above and it would work.I'm aware that we can achieve this with custom properties (https://stackoverflow.com/questions/39692615/is-it-possible-to-have-letter-spacing-relative-to-the-font-size-and-inherit-prop), but I feel like it's still worth adding.
Related to #1814
The text was updated successfully, but these errors were encountered: