-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
default styles have too many styles, styling doesn't match docs #12299
Comments
I fully support this. Right now I must override block styles with !important and this is a mess. It is !important that the blocks have the least styles, if any. My theme provides styles that simply cascade into the blocks. |
Joen said:
The harm is the thousands of existing themes that are styling HTML elements, not blocks, will not look right as soon as the user updates and creates a new post. Their site will not be consistent in itself. The theme should not have to be updated to play nice with a new editor. The editor is outputting HTML just like the old editor did. The theme is styling the HTML. The new styles should not override what the theme is already doing. If the project has to have styles with colors, font sizes, etc. then it should all be in one style sheet that can be opt-in. As it stands now, a theme has to try to opt out, but the styles are so mixed in the theme has to override too much. At the very least, the separation of styles between block styles and editor element styles should be complete (two separate files). |
Thanks for the followup. (For others readon, Joy is referring to a conversation we had in Slack here). I asked for elaboration because I too want to make sure editor styles, theme styles and frontend styles play nicely with WordPress themes, new and old. I have made countless pull request to fix issues and bugs around this, to make sure the theme developer is empowered to make something great. So I think we strongly agree on the overall goal, which is to make sure themers have control. And I volunteer my services to help improve this situation. However in order to be able to submit pull requests, I need to act on specific issues. For example, you mention "new styles should not override what the theme is already doing". To address issues around this there are a number of issues around CSS specificity:
To the larger issue around what is the role of Gutenberg and what is the role of the WordPress theme, there's also this meta ticket: #9534 As a blanket statement, I do not agree that Gutenberg should provide zero CSS at all, unless the user opts in. There are a number of reasons for this:
As with all things Gutenberg, things will evolve and be revisited as we go, and as we learn what works and what didn't. But the above is context for why it's not as simple as it might sound on the face of it. The way we improve this is by pull requests, and the best pull request is small and specific and as noted, I'd love to help here. What issues are not yet ticketed separately, that I may start to address? |
Well, I never said that. I said that it should not style the common things that themes style like colors, font size, padding, margin. It should use whatever the environment provides for how the HTML looks. I'm referring to blocks, not editor UI elements.
That's not true. I started by looking at GB posts in 4,9,8 without GB. I wanted the users of my theme to be able to try GB and have blocks, but if they decided to not use GB, it would still look okay. So even before I added styles, the cover blocks were okay, because the background image is in a style attribute and the text is on top of it. I can add padding and min-height and font-size, but it isn't necessary.
Yes, but I had a block with that in order to test, and it was styling it with colors that have nothing to do with my theme colors. If it's there at all, it should be in theme.css, not style.css. And it should be faint rgba gray, not plain gray. But my theme already stripes the tables by default, so it should be opt-in because it's the new thing. Existing themes can already have that.
It makes no sense to say that "what you see is what you get", but only if your theme opts-in to the front end. If theme.css is optional, it should apply to both back and front. So it should not be loaded unless the theme opts-in. How else can the theme make it match? Does it make sense for the theme to have to overcome theme.css styles in the editor, to match the front where they aren't loaded? Why make it so hard? The editor is just the place to enter content. It shouldn't be concerned at all with how it looks.
I disagree with this. The solution is for the editor to stick with adding and removing classes, and letting the themes and plugins supply the CSS for those classes.
This is untrue. I have reviewed a lot of themes. Most style every HTML element, especially if they use some sort of reset CSS. The editor isn't doing something new. It's just HTML. It looks fine even if unstyled. But that is not the concern of the editor!
As I said in the original post, the biggest problem is that what the docs say doesn't match what happens. I think it's because the styles ended up in style.css instead of theme.css. So if they are to remain, they should be separated. I would urge you to consider that theme.css should be consistently applied. Whether it is opt-in or opt-out, it should be the same on front and back end. I would vote for opt-in, so that people that start creating posts with blocks won't have a quirky mixture of styles on their sites that they can't control. They might have to change themes or modify their child theme, but they shouldn't be forced to do that just to get rid of those styles. |
My editor-style.css file for my custom theme contains the same rules as my main style.css file but it contains !important at the end of each line. Why? |
I am going to inject some comment here about this, because I think it has merit to what everyone is experiencing and saying. See my current post at WordPress.org about the annoyance of Gutenberg / WordPress 5.0 on image captions. https://wordpress.org/support/topic/image-caption-poorly-placed-on-page-gutenberg-annoyance/ With the response of the moderator in that post string, saying that the image caption and image are, by default, centered per Gutenberg's specs. That by default, it render the same way on a published page. My post includes screenshots, where I created a new page, inserted a title, basic text then an image below it with a caption "image caption", using No additional styling. The image was aligned left, the caption was middle of the page which was really offset and not aligned with the image. Based on what the moderator said about the WordPress 5.0/Gutenberg default, the image and caption are apparently to be center on the page. If that is the case, then the "defaults" for Gutenberg/WordPress 5.0 are over-riding the standards & defaults of CSS3. By over-riding the CSS3 standard defaults for elements, Gutenberg is essentially acting in place of the theme when it shouldn't. Example, these are the CSS3 alignment / styling standards-defaults of the following elements,
Per the CSS3 standard, the image and text are never aligned center by default. To align text and images to center requires CSS styling added to the mix. What does this say? It says that WordPress 5.0 is creating a huge headache by stepping over the CSS3 standard/defaults. This will create a huge issue with countless WordPress sites where the content was published using CSS3 default alignments and styling because now Gutenberg is acting in place of a theme which it should never do. The concept of a block page builder is an attempt by WordPress to compete with the growing popularity of Page builders like WP Bakery, Elementor, etc. In doing so, they have completely lost sight of what a WordPress editor is suppose to be and do. At no time should the WordPress editor start adding different styling, automatically, that supersedes or ignores CSS3 defaults. Any styling beyond the CSS3 defaults is done by the user or theme developer. This means, taking the image and caption example, the editor has to provide, by default, both image and caption to show per CSS3 defaults, which means align left. Then a WordPress user or theme developer can work from that base-line standard to make changes to element styling using the editor (WordPress user) or using the theme (theme developer). ... but they can't now because WordPress 5.0 has screwed with the CSS3 standard. The headaches and extra work this injects into using WordPress is astounding, all because WordPress wanted to compete against page builders. What should WordPress do to make Gutenberg work? Rewrite all of it, get back to the standard and don't screw with the standard. Leave the extra styling to the user to how they want the image to appear on the page and let the developers work their theme, but all of them will be working from the SAME standard, the CSS3 standard. |
Excellent point and it goes along with a suggestion I've been wanting to open a discussion on. The "default" styles should only include those needed for function and layout. Opinionated styles should be used only when necessary so that older themes don't have a broken layout.
|
I also vote that only structural elements of a block, that are particular components of a specific block layout, be styled by default. Any overrides of expected defaults, such as formatting tables with visible styles or centring text because it looks better, should be opt-in. The new editor is not a place to put opinionated style rules because those opinions should, in almost all cases, be decided by the users and not enforced on them by the editor. |
Actionable: start by removing the color styles, especially for caption text. See this forum topic: https://wordpress.org/support/topic/edit-wp-with-white-on-white-and-black-on-black-text/ |
A simple solution to most issues related to specificity or opinionated styles will be CSS Custom Properties. There's no <=IE11 support but I see no reason why we couldn't go ahead and have the variables in place. Browsers that don't support Custom Properties will just ignore them and use the fallbacks we have there now. I'm currently doing something like this in my CSS:
To override that you would just do something like:
Specificity and opinionated styles become a non-issue. (for non-IE browsers) |
@m-e-h I would love to see Custom Properties used! But it doesn't quite solve the problem for styling things that shouldn't be styled by the editor (think of legacy themes displaying new block posts). If the opinionated styles were moved from style.css to theme.css, though, it would help a lot. That's what this issue is about. |
About the Custom Properties. It isn't supported in IE11. Also, I thought we were meant to be minimising the amount of CSS that we used. |
This PR moves the color and font size styles for captions to a separate CSS file that themes opt in to. As a reminder, we have style.scss, which contains structural and base styles that are loaded in the editor and the theme. There's editor.scss which is only loaded in the editor. There's theme.scss, which is loaded in the editor and the theme if the theme opts in to them. Addresses one item surfaced in #12299 (comment), props @joyously.
Thanks for the suggestion. I had gone to weekend when the tip came in, but I'm back in my seat and there's a PR in #14366. |
You're right @joyously. Custom properties would do nothing to help existing themes. Or any theme really since it's browser support is still around just 90%. @jasmussen That's awesome! Hopefully similar moves to |
This PR moves the color and font size styles for captions to a separate CSS file that themes opt in to. As a reminder, we have style.scss, which contains structural and base styles that are loaded in the editor and the theme. There's editor.scss which is only loaded in the editor. There's theme.scss, which is loaded in the editor and the theme if the theme opts in to them. Addresses one item surfaced in #12299 (comment), props @joyously.
* Try: Move color and font size from captions to theme This PR moves the color and font size styles for captions to a separate CSS file that themes opt in to. As a reminder, we have style.scss, which contains structural and base styles that are loaded in the editor and the theme. There's editor.scss which is only loaded in the editor. There's theme.scss, which is loaded in the editor and the theme if the theme opts in to them. Addresses one item surfaced in #12299 (comment), props @joyously. * Address feedback. * Address feedback. Create new vanilla block styles location. * Address margin feedback. * Address feedback.
Agreed with the suggestions to separate structural/layout styles from styles about font/color/line-height/. Can we go a step further and break up The use case I see is a theme that has its own styles for the Cover block, and so wants to dequeue Core's styles for that block, but doesn't have custom styles yet for the Gallery block, and so wants to keep using Core's styles for that block. Right now, the theme's options are:
|
Just modernized a theme i bought on *****forest by making a child theme to be compatible with GB. Used the latest Theme Unit Test data to compare the looks in back-end and in front-end. |
What if WP would watch in the background and in case a new theme gets activated a server-side script would parse through any .css file of the theme to evaluate which html tags and GB classes have defined rules in the theme/child theme and in such cases copy those rules. Then also evaluate style.min.css and take from that file only rules for such elements, that have not been styled within the theme. As a last step build a new .css file that is a merged output of the 2 above described processes and I also could imagine going one step even further and do something similar for the editor styles in the back-end and ultimatively get rid of the need for a separate I know it is probably quite different from that what is currently implemented but that way we could avoid css rule duplicates, unwanted and unexpected overrides, and also an opt-in that is currently splitted up in 2 steps. |
Because that's hard to do and there are rules added dynamically, depending on the page and depending on the options the user chooses. |
Does this project use a linter for CSS? If so, could there be rules to disallow certain properties in the style.scss files, like color, font-size, text-align, background-color, maybe even padding and margin? These would all be allowed in theme.scss. One of the other specific rules that needs moving is
There is a color style and font-size style on the Latest Posts date.
There are margins on the figcaption.
The button styles are so difficult! Why was round made the default? The outline button style has colors and a particular border style.
But that only overrides part of the "default" button style. Imagine that the theme has a dark background and light text and an outset border style. The problematic part is the color and border and radius and font size and padding and margin and text-align. I still don't think there should be a Button block because that is bad semantics. Links should be identifiable as links, leaving buttons for scripts to use in forms.
OMG! Cover block styles! This is a nightmare to override. What if the theme just uses text-shadow, and the color doesn't matter? Why does the editor have to interfere?
Gallery block captions are very opinionated. In my theme, I don't even attempt to restyle. But it shouldn't be that way. The figcaption style should apply equally across images and galleries. Please move the whole gallery figcaption style from style.css to theme.css. The selector is very specific: Media and Text block has The drop cap style has a font properties, that should be moved.
The Quote block now has a class for default (didn't used to). The The pull quote has some text-align and border and background:none and margin and padding. These are just the blocks that I have in the Theme Unit Test data. I'm sure there are others and will be more as we go along. That's why I am asking about some linting rules that could be applied to the project, so that these things are caught automatically. |
@joyously This is definitively a very big headage of the WordPress default styles for blocks like the button or cover block. But it seems there is nothing happened in the past. For example the outlined button can't have custom text color or background color, because the WordPress default style I think it's time for the gutenberg team to rethink this. A solution especially for the outlined button default styles could be:
Instead of the current style:
This approach in the WordPress default block style would also solve other issues. |
I've personally come to the point where there really is no way around completely removing all core styles. It's already bad enough when you need to use But then you manually need to maintain all block styles on your own keeping them in sync with version updates which is hard. What would be great is if those styles would be broken into pieces that can then be removed individually. So e.g. I can just remove the styles for anything related to the column block which is much less work to maintain. (On a sidenote since I looked into building the |
Since I just came across this issue again - I've blogged about this some weeks ago: https://kraftner.com/en/blog/understanding-wordpress-block-css/ Also something new has happened recently that might offer another angle to approach this - loading styles for blocks separately. |
Can we talk about everything changing with every update. HTML structure changing among other things. Gutenberg was meant for non-programmers to use, like my clients, but I fight to keep my clients out of Gutenberg because if they see broken blocks (broken because the markup changed in an update) they will blame me, and think my work is shoddy. If they click "attempt block recovery" and the front end breaks even a tiny bit, again, they blame me. Seems like weekly there is a mysterious problem like cover backgrounds suddenly stretch to fit on mobile, that's new. I actually tell all my coworkers. never ever ever use covers, just make a group and give a it background with CSS, because covers can't be trusted. They have changed 3 times in the last 2 years, and I don't want to go though fixing them again. I guess should I give constructive criticism. |
@joshlmaxwell I'm all with you. It's very hard to keep up to date when a website is based on the Gutenberg editor. Things that break after every Gutenberg release, and the list of Github problems keeps getting longer. I think the Gutenberg project is too complex and it is very difficult for the Gutenberg team to keep track of everything. We can only hope that things will get better quickly and that a stable basis will be found that is not constantly being reconsidered. |
According to https://wordpress.org/gutenberg/handbook/extensibility/theme-support/
there are some styles that come with blocks. "By default, blocks provide their styles".
Then the list of "Opt-in features" is
These last ones seem to contradict each other. How do you opt-in to disable something that is opt-in?
This is the real problem:
This is not what happens. There are styles in build/block-library/style.css that contain colors and font sizes that are shown in the editor and on the front end. They override my theme styles, and the theme does not opt-in to any of the new things.
Searching for 'color' in the style.css file shows at least 100 matches (a bunch of which are the definitions of classes for colors). There are 38 font-size matches. Some are the definitions of font sizes, and those should not be defined in pixels.
There should be no colors, no font sizes, no padding or margin, no text alignment, no text transform that affects blocks. I understand that the editor elements should be styled, but the blocks themselves should not be styled.
I am seeing colors for table striping, button background, pull quote text, figcaption, code background, cover image text, download button text, comment date, post date.
I see font-sizes for figcaption, button text, cover image text, download button, comment text, comment date, post date, paragraph text, pull quote text.
The text was updated successfully, but these errors were encountered: