-
Notifications
You must be signed in to change notification settings - Fork 676
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
[css-fonts] font-weight: bolder and lighter are counter-intuitive #2764
Comments
Allowing |
There's nothing wrong with it Syntax-wise (global keywords aren't handled at that level). Handling global keywords in the middle of other properties isn't problematic either - you can already do that in font-family. ( It's just putting keywords into calc() that's problematic right now. But grabbing the inherited value of a property via a function or something shouldn't be problematic. |
Actually, maybe it's better to have a special value like "bolder" and "lighter" that instead selects the immediately larger or lighter weights available for the current font. In other words, |
I moderately disagree with this. It may not be a problem for (Actually it's not even clear to me whether |
came here via #2764 (reference) The above problem could be fixed if the bolder and lighter keywords would actually do what their name suggests; at least for variable fonts. No need for keyword handling in calc() then. Maybe some variation of Variable Fonts are a thing now! Unfortunately neither "bolder" nor "lighter" move to the next weight variation within a variable font, but act binary as "bold" or "un-bold" aka "normal". That was fine when most ordinary fonts typically featured a binary state for normal/bold as well. Also going bolder or lighter (font wise) within nested elements does not imply moving in steps of 100 only. A variable font could contain just three presets for its the "wght" axis using 200, 400, 600 or any other set of arbitrary numbers between 1 and 1000. With a fallback list of different variable fonts such as Using "bolder" or "lighter" could (should) continiously select the next available weight variation. Here each letter of the words "Fonts" and "Mood" is a set of nested b {font-weight:bolder} /* life could be easy ... */ <!-- crudo ma bello -->
<p>Variable <b>F<b>o<b>n<b>t<b>s</b></b></b></b></b> R <strong>côôl</strong></p>
<p>G<b>o<b>o<b>o<b>o<b>o<b>d</b> Morning</b></b></b></b></b></p>
Today I can do the same thing but with much more effort and have to use an explicit amount of nested B selectors - unlike the oneliner above. I also need to keep the ramp values at a specific start/end point or the result could look choppy when used in a possibly different context. /* ... but it's not ... */
p {font: 200 2rem/1 "League Spartan","Bahnschrift","Source Sans Pro",sans-serif;}
p > b { font-weight: 300 }
p > b > b { font-weight: 400 }
p > b > b > b { font-weight: 500 }
p > b > b > b > b { font-weight: 600 }
p > b > b > b > b > b { font-weight: 700 }
p > b > b > b > b > b > b, strong { font-weight: 800 } Using CSS properties the CSS can become simpler ... p {--w:1 }
p b { font-weight: calc(var(--w) * 200) } but the HTML gets even worse: <p>G<b style="--w:1">o<b style="--w:2">o<b style="--w:3">o<b style="--w:4">o<b style="--w:5">d</b> Morning!</b></b></b></b></p> Cheers. |
And tat is the crux of the issue.
Looking at the definition ( Achieving the desired effect using calc, though, seems like a much better approach. |
With few additional tools, i. e. functions, authors could build individual stepping patterns. :root {
--font-weights: 100, 200, 300, 400, 500, 600, 700, 800, 900;
--i: 4;
}
foo, bar {
font-weight: index(var(--i), var(--font-weights));
}
foo {
--i: max(var(--i) + 1, 9);
}
bar {
--i: min(var(--i) - 1, 1);
} |
[EDIT: my memory failed me miserably onthis. See comments below about the confusion.] Sidenote> increments/decrements could/should work like |
Because that's not allowed and immediately causes the variable to be invalid-at-computed-value-time ^_^. |
Hopefully you had consistent reults i.e. that didn't work anywhere. CSS is declarative. All uses of a variable have the same value. There is no order of execution. It is no an imperative programming language. That and other reasons (inheritance, initial value) is why 'CSS Variables' is now termed 'Custom Properties'. |
You're right of course! 🤐 --val: calc(2 + 2);
--foo: calc(2 * var(--val)); /* Edge chokes */ The snippet's from a comment in an experiment I did ages ago toying with hsl() utilizing tons of calc() and var()s en masse to build basic color schemes and ramps. I can't reproduce this today as the above code for |
How about adding two new functions with the same names as the existing keywords? font-weight: bolder(250); /* add 250 to the weight */
font-weight: lighter(250); /* subtract 250 from the weight */
font-weight: bolder; /* use the legacy behavior */ This doesn’t require a CSS-wide change. |
Yes, I should have checked my made-up code better. (In actual production code, Iʼve only used very simple vars yet.) I could have tried solving it with counters or the current font weight or the actual width of As for dedicated functions suggested by @litherum, why not more generic ones? For instance: |
coming back to @tabatkins earlier remark:
Since multiple weights are a variable font thing anyways, I'd then suggest to use a property that already officially deals with it, instead of teaching and old dog new tricks. font-variation-settings: "wght" calc( var(--normal) + 250); Not sure if this is also animatable (some would certainly want that). I remember a CodePen doing that, but there might've been some JS involved - I don't remember that ;) So if there were a "function or something", maybe sth. like this could get us much further: font-variation-settings: "wght" calc( current() + 250);
font-variation-settings: "wght" calc( current(wght) + 42 * 100); I have no opinion onits name, but thing is: this is a multi value property like there are many in CSS. The syntax and smartness of this "gimme the current|inherited value" function will be interesting to draft and for implementors to code :) Cheers. |
We already have generic ones. They are If a generic function is preferred, we should close this issue as “no change” because |
Right. In particular, this sets the |
Dedicated increment and decrement functions would avoid this new concept, but they would be limited to addition and subtraction, respectively, when you sometimes want multiplication or division (e g. in font size steps). In conclusion, they would probably be an inferior solution. If a generic function is preferred, we should rename this issue (or create a new one). |
oh, I forgot that part :/ Thanks for the heads up! --mo-variations: "wght" 300, "xhgt" 0;
font-variation-settings: "wght" calc( current() + 250) , var(--mo-variations); [edit typo] |
I'm not sure if it will be possible with future
calc()
improvements, but it would be great if it was possible to write:As opposed to
bolder
andlighter
that are really hard to use and that never do what the designer wants.Thanks in advance.
The text was updated successfully, but these errors were encountered: