Opened 22 months ago
Last modified 5 months ago
#60408 new defect (bug)
Twenty Nineteen: Theme block styles are not applied to blocks in the widget area
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Future Release | Priority: | normal |
| Severity: | normal | Version: | 5.8 |
| Component: | Bundled Theme | Keywords: | has-patch changes-requested 2nd-opinion |
| Focuses: | css | Cc: |
Description
Twenty Nineteen adds extra styling for some blocks, but on the front, the styles use
the class names .entry .entry-content as part of the selector:
.entry .entry-content .wp-block-button .wp-block-button__link:not(.has-background) {
background-color: #0073aa;
}
So the styles are applied in the post content area, but not applied to blocks placed in the widget area.
The blocks in the widget area on the front does not match what is in the widget admin screen.
Attachments (4)
Change History (13)
#2
@
19 months ago
- Focuses css added
- Milestone changed from Awaiting Review to Future Release
- Version set to 5.8
#3
@
17 months ago
- Keywords needs-testing added
Adding the keyword to get testing on this, thank you.
#4
@
16 months ago
@sabernhardt @karmatosed Hi!
In your opinion, what would be the preferred solution for making sure that the theme block styles are applied to blocks in the widget area, not only the post content?
- Apply the styles by adding a selector with
.widget-area - Removing
.entry .entry-contentselector
Relevant files:
https://core.trac.wordpress.org/browser/branches/6.6/src/wp-content/themes/twentynineteen/sass/blocks/_blocks.scss#L127
#5
@
16 months ago
I have not tried to implement any of these, but I can share my preferences for the concepts.
- If
.entry .entry-contentcan be removed without changing the post content's appearance, that would be my preference. However, those styles may need a higher specificity to override something. - If the selectors need higher specificity but one class is enough, I would suggest replacing
.entry .entry-contentwith.site. The color patterns function uses.entry .button(without.entry-content), which suggests that that needed one extra class to override a selector. - If it needs two class-level selectors,
:root .sitemight work. - Hopefully the stylesheet would not need to copy all of those selectors with a
.widget-areavariation.
This ticket was mentioned in PR #9019 on WordPress/wordpress-develop by @shubhtoy.
5 months ago
#6
- Keywords has-patch added; needs-patch removed
This PR addresses a CSS specificity issue in the Twenty Nineteen theme where Gutenberg block styles, particularly button styles, were not being applied consistently across different areas of the site due to insufficient selector specificity.
### Problem
The original CSS selectors used .entry .entry-content as the base, which meant:
- Block styles only applied in post/page content areas - Blocks in widget areas (like footer widgets) didn't receive the theme's custom styling
- Inconsistent visual experience - The same button block would look different in the content area vs. widget areas
- Backend/frontend mismatch - Widget editor showed one appearance while frontend showed another
Example of the issue:
/* Before - only applies in post content */
.entry .entry-content .wp-block-button .wp-block-button__link:not(.has-background) {
background-color: #0073aa;
}
/* After - applies site-wide with higher specificity */
:root .site .wp-block-button .wp-block-button__link:not(.has-background) {
background-color: #0073aa;
}
### Changes Made
- Increased CSS specificity by changing selectors from .entry .entry-content to :root .site
- Applied to all Gutenberg blocks including:
- Button blocks (primary focus of this fix)
- Pullquote, Quote, Image, Cover blocks
- Gallery, Separator, Table, File, Code blocks
- Column, Group, Latest Comments blocks
- Font size and color utility classes
- Maintains visual consistency across post content, widget areas, and other contexts
- Ensures backend-frontend parity for block appearance in widgets
### Steps to Reproduce the Original Issue
- Go to Appearance > Widgets
- Add a Button block to a widget area (e.g., Footer 1)
- Configure the button with default styling (no custom background color)
- Backend: Button appears with Twenty Nineteen's blue theme color (#0073aa)
- Frontend: Button appears with browser default styling (not blue)
- After this fix: Button appears consistently blue in both backend and frontend
### Technical Details
The :root .site selector provides higher specificity than the original .entry .entry-content while still being scoped to the site container. This ensures the styles apply everywhere blocks can appear while maintaining the theme's design integrity.
#### Specificity comparison:
- Before: .entry .entry-content (0,0,2,0)
- After: :root .site (0,0,1,1) with :root pseudo-class providing higher effective specificity
### Artificats (Screen Recordings)
- Before:
https://github.com/user-attachments/assets/68640a00-97b0-46ae-9f46-415fc6cb84c4
- After
https://github.com/user-attachments/assets/9465b39b-b9f3-48d6-bb82-5b58a8038ce0
Trac ticket: #60408
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.
#7
follow-up:
↓ 8
@
5 months ago
- Keywords changes-requested 2nd-opinion added; needs-testing removed
@shubhtoy review code as you are sending a full unnecessary new file
Also, I'm not 100% convinced about that root solution @sabernhardt, can you have a second look when you have a minute?
#8
in reply to:
↑ 7
@
5 months ago
full unnecessary new file
PR 9019, still in draft status, contains two files: _blocks.scss and style.css. Twenty Nineteen patches need to edit both the SCSS and the compiled stylesheets. Front-end style changes should include a third file, style-rtl.css. @shubhtoy You probably need to run npm run build a second time.
not 100% convinced about that
rootsolution
The :root .site selector has a specificity of 0-2-0, same as .entry .entry-content. While I would prefer to reduce the specificity if possible, :root .site theoretically is safer, with less chance of regressions in the content area.
#9
@
5 months ago
Thanks for the feedback!
You're absolutely right — I missed including style-rtl.css in the patch. I’ll make sure to run npm run build again and include all the necessary compiled files in the next update.
Regarding the :root .site selector — I understand the concern about specificity. My initial thought was to keep it scoped to reduce potential side effects, but I’m open to adjusting it if you think a lower specificity would be safer or more in line with the theme’s conventions. Happy to revisit that part based on your input.
Let me know what you think, and I’ll update the PR accordingly.
The button block in the widget area, on the front of the site