Video yükleniyor...

Video Yüklenemedi

Ana Sayfaya Dön

I think I figured out how to create responsive type scales with composable CSS utilities, thet lets you scale linearly between exact pixel values (this is important if you want to align exactly with a type scale, rather than just scale type on a case-by-case basis) 🧵

20,984 görüntüleme • 2 yıl önce •via X (Twitter)

10 Yorum

Tobias Ahlin profil fotoğrafı
Tobias Ahlin2 yıl önce

I've summarized the technique at length here but here's a quick breakdown of the problem and solution. I've always assumed that this has been impossible to pull off, since you currently can't divide a pixel value with another pixel value using CSS calc()

Tobias Ahlin profil fotoğrafı
Tobias Ahlin2 yıl önce

This calc() restriction is going to be relaxed in the css-values-4 spec ( but for the time being, that's the restriction we're dealing with. How do we then divide, for example, the current viewport width with the maximum viewport width, to know how far...

Tobias Ahlin profil fotoğrafı
Tobias Ahlin2 yıl önce

we are between two viewport sizes, so that we can scale a font size accordingly? Since we currently can't convert pixel numbers to unit-less numbers, we have to go the other direction → convert unit-less numbers to pixels. We can define all of our variables without units:

Tobias Ahlin profil fotoğrafı
Tobias Ahlin2 yıl önce

…and then convert them to pixel values by multiplying them with 1px when we need them as pixel values. We can then "unlock" the calculation that at first hand can seem impossible to perform with the current restrictions:

Tobias Ahlin profil fotoğrafı
Tobias Ahlin2 yıl önce

Then we can set new variable values with utility classes, to create composable type scales:

Tobias Ahlin profil fotoğrafı
Tobias Ahlin2 yıl önce

The demo in the first tweet is then created by combining these classes:

Tobias Ahlin profil fotoğrafı
Tobias Ahlin2 yıl önce

Again, all the details are here: significant limitation of this technique right now is that we can't use rems (this only works with pixels), but that should be resolved with the relaxed CSS calc() specs 👀

XH profil fotoğrafı
XH2 yıl önce

Just an FYI, in case you run into this edge case on Safari text reflow (gave me a lot of headache)

Tobias Ahlin profil fotoğrafı
Tobias Ahlin2 yıl önce

Oh dear, that’s why!

Igor bedesqui profil fotoğrafı
Igor bedesqui2 yıl önce

omg this is AMAZING

Benzer Videolar

Elon Musk just reduced ten thousand years of human progress to a single number. It didn’t even register. Musk: “How do you decide what progress a civilization has made? One of the most objective ways to do that is the amount of power that any given civilization has been able to harness.” Not GDP. Not military power. Not cultural reach. Energy. Captured and put to work. The only variable the universe respects. A Soviet astrophysicist named Kardashev turned this into a scale. Type I harnesses the energy of its planet. Type II harnesses its star. Type III harnesses its galaxy. There is no Type Zero. We’d need one. Musk: “Right now, we’re very low on the Kardashev Type I scale. We currently use much less than a trillionth of the power output of the sun. A trillion is a million times a million. We are practically nowhere on the Kardashev Type II scale.” Every reactor. Every dam. Every turbine. Every solar panel. Every barrel of oil ever pulled from the ground. Combined. A trillionth of the sun. Ten thousand years of civilization. On the only scale the universe uses to measure intelligent life, we are statistically invisible. The rest of the world argues about which fuel to subsidize. Elon is building at the only scale this equation respects. Tesla. Solar. Batteries. Starship. Every company he runs is aimed at the same point on the Kardashev Scale. That’s not a business empire. That’s a blueprint for moving a civilization up a scale it doesn’t know it’s on. The Kardashev Scale doesn’t care about your politics. Doesn’t count your GDP. Has no room for your borders or your wars. It reduces every civilization in the universe to a single number. The universe keeps one scoreboard. It doesn’t care who reads it. Elon builds like he has.

Dustin

28,355 görüntüleme • 1 ay önce