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

Global Styles: Root font-size utility classes mismatch theme settings. #21759

Closed
allancole opened this issue Apr 21, 2020 · 5 comments · Fixed by #21969
Closed

Global Styles: Root font-size utility classes mismatch theme settings. #21759

allancole opened this issue Apr 21, 2020 · 5 comments · Fixed by #21969
Assignees
Labels
[Block] Paragraph Affects the Paragraph Block CSS Styling Related to editor and front end styles, CSS-specific issues. [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Status] In Progress Tracking issues with work in progress

Comments

@allancole
Copy link

While testing the new font-size options in Gutenberg 7.9, I noticed there’s some additional CSS on the frontend that overrides my the font-sizes I have set in CSS and the add_theme_support() editor font-size settings.

These screenshot illustrates the issue:

image

Additionally, in my functions.php file I have this snippet:

// Add custom editor font sizes.
add_theme_support(
	'editor-font-sizes',
	array(
		array(
			'name'      => __( 'Large', 'themename' ),
			'shortName' => __( 'L', 'themename' ),
			'size'      => 24,
			'slug'      => 'large',
		),
	)
);

(only large is shown here for context, but all the editor font-sizes have this issue)

Expected behavior
I expected Gutenberg to accept the font-sizes I set both in functions.php and my theme’s stylesheet but both are getting overwritten because Gutenberg is adding :root to the font-size selectors.

I recognize I could fix this in my theme but adding the :root selector to my stylesheet’s font-size utility class selectors, but other Gutenberg utility classes like .has-background or .alignwide do not use :root in their selectors.

For consistency, can we simply remove the :root selector here?

Editor version (please complete the following information):

  • WordPress version: 5.4
  • Gutenberg plugin version: 7.9.1

Desktop (please complete the following information):

  • Mac OS
  • Chrome (version 80.+)
@kjellr kjellr added [Block] Paragraph Affects the Paragraph Block [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. CSS Styling Related to editor and front end styles, CSS-specific issues. labels Apr 21, 2020
@kjellr
Copy link
Contributor

kjellr commented Apr 22, 2020

cc @youknowriad and @nosolosw, since this is related to #21153.

Since there's no variable being used at the moment, the suggestion in the other thread isn't possible.

Themes can override this by changing their custom font size style specificity to :root .has-tiny-text-size, but that's quite uncommon. Currently, the default Gutenberg value overrides the theme-provided style value in most themes I've tested.

Twenty Twenty specifies its font size variables using p.has-tiny-text-size, which does override it. The downside there is that the style doesn't work on other text-based blocks with a font size control, like the Heading block. Not sure the best way forward on this one.

@youknowriad
Copy link
Contributor

I believe these themes you're talking about are not using the regular editor-styles mechanism right?

@kjellr
Copy link
Contributor

kjellr commented Apr 23, 2020

The issue persists whether or not it's enqueued with add_theme_support('editor-styles') or not — it's just related to the theme's specificity for the styles.

Twenty Twenty does not use that method, but the styles are not overridden because of the extra specificity of the p tag in the rule.

Whereas in the theme @allancole and I are building, we do use the regular mechanism, but our usual .has-tiny-text-size style is overridden.

@oandregal
Copy link
Member

#21969 reverts the :root addition, which is a leftover of the experiment we did with CSS variables by default that we later reverted.

@aduth
Copy link
Member

aduth commented Apr 29, 2020

Even without :root, I have to imagine this is still pretty fragile, since both would still have the same specificity, it depends on the load order of stylesheets. If theme styles are meant to override Gutenberg's, ideally it should have a higher specificity.

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 CSS Styling Related to editor and front end styles, CSS-specific issues. [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Status] In Progress Tracking issues with work in progress
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants