WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.37k stars 4.15k forks source link

Add relative units for font size option #23323

Open iamtakashi opened 4 years ago

iamtakashi commented 4 years ago

The custom font size option is really useful, but the lack of relative units has been a problem to make patterns work well in both large and small screens.

It'd be great if we could have some the relative units, just like the cover block height control.

Screenshot 2020-06-19 at 18 39 24

With the vw unit, this sort of type treatment would be possible, I think.

Screenshot 2020-06-19 at 18 41 34

I've seen this topic has come up before, and I'll apologise if there is a better thread to discuss this. If there is please point me at there.

carolinan commented 4 years ago

Related: https://make.wordpress.org/themes/2020/05/20/block-based-theme-meeting-notes-20-may-2020/

https://github.com/WordPress/gutenberg/pull/22505

aristath commented 4 years ago

Expanding on this one, it would be useful to just have a freeform option. Values don't necessarily need to be 10px, 2em, 3vw etc... Some cases require more elaborate values. Maybe I want to use calc(14px + 0.5vw) and have responsive typography. Or maybe I just want to use clamp(). Or even just use a css-variable and type var(--base-font-size).

Forcing users to pick a numeric value and a unit will cover a lot of cases, but not all. It will still limit things and prevent valid use-cases that make sense.

jorgefilipecosta commented 3 years ago

I agree with what is being said here. Ideally, the font size picker component would be expanded to support string values. When it can parse things like "1em" it would render relevant pickers with the correct units. If it can not parse because it is a complex value like calc(14px + 0.5vw) it would show a simple input field with the string.

The same would happen for all controls where we accept value/units or more complex CSS.

mtias commented 2 years ago

This is supported now.

iamtakashi commented 2 years ago

This is supported now.

@mtias I can see px, em, and rem units available now, but vw and vh aren't yet available. Am I missing something?

Screenshot 2022-05-26 at 18 03 47

It depends on #24480, but if that will take more time, I think it's worth considering adding vw and vh as well. What do you think?

mtias commented 2 years ago

Ah, sorry, I misread :)

iamtakashi commented 2 years ago

That's ok. Thanks for reopening!

flabernardez commented 6 months ago

This option will be added soon?

I really need vw vh and calc or var options to fonts size 😄

carolinan commented 5 months ago

@iamtakashi @flabernardez @beafialho @WordPress/block-themers @WordPress/outreach Would having vw and vh units in the custom font size picker* be useful even if it is not combined with clamp()?

(*The control in the Typography panel where you select a completely custom font size instead of using a preset)

iamtakashi commented 5 months ago

Would having vw and vh units in the custom font size picker* be useful even if it is not combined with clamp()?

It can be useful. Here's a recent example of using the vw unit for this theme: https://surrealist.mystagingwebsite.com/. I see this kind of design treatment, a single word spanning the screen, more often in the wild lately. When the editor recognises the unit, the user can adjust the size easily depending on their content.

However, while working on the theme, I realised that the editor already recognises the vw unit if it's first added in the code editor. I was pleasantly surprised!

<!-- wp:site-title {"textAlign":"center","isLink":false,"style":{"typography":{"fontSize":"20vw"}}} /-->

CleanShot 2024-04-11 at 10 36 43@2x