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

Better scope the "Vanilla Block Styles" CSS selectors #17702

Closed
afercia opened this issue Oct 2, 2019 · 2 comments
Closed

Better scope the "Vanilla Block Styles" CSS selectors #17702

afercia opened this issue Oct 2, 2019 · 2 comments
Labels
[Package] Block library /packages/block-library [Type] Bug An existing feature does not function as intended

Comments

@afercia
Copy link
Contributor

afercia commented Oct 2, 2019

Describe the bug

We currently faced a CSS conflict issue with our plugin meta box and after some digging it appears Gutenberg uses some very general CSS selectors in the block-library stylesheet. See:

/**
* Vanilla Block Styles
* These are base styles that apply across blocks, meant to provide a baseline.
* They are applied both to the editor and the theme, so we should have as few of these as possible.
* Please note that some styles are stored in packages/editor/src/editor-styles.scss, as they pertain to CSS bleed for the editor only.
*/
// Caption styles.
// Supply these even if the theme hasn't opted in, because the figcaption element is not likely to be styled in the majority of existing themes.
// By providing a minimum of margin styles, we ensure it doesn't look broken or unstyled in those themes.
figcaption {
margin-top: 0.5em;
}
// Apply some base styles to blocks that need them.
img {
max-width: 100%;
height: auto;
}
iframe {
width: 100%;
}

While I do understand the need to target some elements across all blocks (which by the way goes a bit against the principle of isolated, reusable, components), it appears some of thes CSS selectors aren't scoped at all and they target all the related elements. Even the ones in the UI added by plugins, whether it's a meta box or a sidebar or anything else.

They even target any related element in the WordPress admin UI, which may potentially produce breakages. I'd tend to think this shouldn't happen and these selectors should be better scoped.

Specifically:

  • the img type selector targets any image in the edit post page: I'd say this is the most important case
  • minor: same happens with the figcaption and iframe selectors: figcaption and iframe are likely less used by plugins but there's a potential of breakage anyways.

To my understanding, the main goal of these "Vanilla Block Styles" is to provide some baseline styles for all the blocks. If so, seems to me they should at least be better scoped with an additional selector that targets the blocks area and excludes all the rest of the page.

@afercia afercia added [Type] Bug An existing feature does not function as intended [Package] Block library /packages/block-library labels Oct 2, 2019
@paaljoachim
Copy link
Contributor

I am wondering if this issue is still valid.

@WordPress/gutenberg-core

@tellthemachines
Copy link
Contributor

The vanilla styles have been removed, so we can close this issue now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Block library /packages/block-library [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

3 participants