Skip to content
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

Add relative units for font size option #23323

Open
iamtakashi opened this issue Jun 19, 2020 · 10 comments
Open

Add relative units for font size option #23323

iamtakashi opened this issue Jun 19, 2020 · 10 comments
Labels
[Block] Paragraph Affects the Paragraph Block [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Enhancement A suggestion for improvement.

Comments

@iamtakashi
Copy link

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.

@kjellr kjellr added [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Type] Enhancement A suggestion for improvement. Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Block] Paragraph Affects the Paragraph Block labels Jun 19, 2020
@carolinan
Copy link
Contributor

@aristath
Copy link
Member

aristath commented Aug 11, 2020

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.

This was referenced Sep 17, 2020
@jorgefilipecosta
Copy link
Member

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
Copy link
Member

mtias commented May 23, 2022

This is supported now.

@mtias mtias closed this as completed May 23, 2022
@iamtakashi
Copy link
Author

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 mtias reopened this May 26, 2022
@mtias
Copy link
Member

mtias commented May 26, 2022

Ah, sorry, I misread :)

@iamtakashi
Copy link
Author

That's ok. Thanks for reopening!

@flabernardez
Copy link

This option will be added soon?

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

@carolinan
Copy link
Contributor

@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
Copy link
Author

iamtakashi commented Apr 11, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Paragraph Affects the Paragraph Block [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Enhancement A suggestion for improvement.
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

7 participants