The math of CSS locks
fvsch.com
fvsch.com
It's amusing to see "calc" in CSS. You're only allowed the operators + - * /. No functions. Want to bet people start demanding user-defined functions?
font-size, line-height = function(viewport_width, max, min)
in CSS. I think a closer analogy would be comparing it to timing/easing functions, rather than linear interpolation.Doesn't Sass/SCSS already do that?
"Eventually"
The word "clamped" should have been used instead of "lock". They just want the text size to scale linearly with page width, but they want to "clamp" the text size so that it always stays within some reasonable (min, max) range. They could have also called it "piecewise linear".
There are two water levels, high and low side of the lock.
The lock smoothly transitions you from one level to the other.
A media query without the transition would be like navigating a boat down a waterfall rather than down a lock; jarring!
I've got a demo of the lock-style implementation they are talking about in the article here: http://codepen.io/tomhodgins/pen/QEVbwR
And another, JavaScript-powered version that I think is closer to how min-font-size or max-font-size would work if implemented as a CSS property here: http://codepen.io/tomhodgins/pen/bZxvjg
The reason I ask is because I've implemented similar techniques in projects before, and from experience I ran into a few situations where (for example) text would wrap at undesirable locations (such as titles / headings) during the transition while I would resize the window's width. So if anything it may be interesting to extrapolate this technique so that the derivative of the function is slightly smaller on the small end of the spectrum, and slightly larger on the big end. Or maybe a shape similar to a sigmoid function?
I think most word wrap issues could be avoided with implementation of the text-balance spec. (Pretty sure this is a part of css4) Polyfill Example: http://webplatform.adobe.com/balance-text/demo/index.html
As for changing linear interpolation to easing, I can't think of a good way to do that off the top of my head. It could be made in js but native css would be better.
It does seem like a great use case for houdini specs (if they do come out) where just like the dom is accessable from js, the cssom would also be available so you could make a new css rule with a js implementation. Really good read on that: https://www.smashingmagazine.com/2016/03/houdini-maybe-the-m...
I'm not sure if it's possible to express an in-out easing function inside `calc`, but you might be able to set a halfway point and use two easing functions.
I wonder why there is no centimeters or something in css, maybe because historically it didn't matter and was not known to the browser...
I can totally understand how CSS expressions would be re-evaluated due to a repaint (resizing the window, manipulating DOM elements with javascript, etc)... but it doesn't make any sense that simply moving your mouse would cause this.
Paul Irish has pretty complete list of what triggers repaint here: https://gist.github.com/paulirish/5d52fb081b3570c81e3a
I remember having a lot of trouble with this when reading medium.com posts on mobile