Make WordPress Core

Opened 4 weeks ago

Last modified 3 weeks ago

#63143 new defect (bug)

Twenty Nineteen: Inconsistent spacing between Table Caption and Table in Table Block

Reported by: sainathpoojary's profile sainathpoojary Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version: 5.4
Component: Bundled Theme Keywords: has-testing-info changes-requested
Focuses: css Cc:

Description

In the Twenty Nineteen theme, the Table block displays inconsistent spacing between the table caption and the table.

  • Editor: The caption is directly attached to the table without any spacing.
  • Frontend: There is noticeable spacing between the table caption and the table, creating a visual discrepancy.

Steps to Reproduce

  1. Activate the Twenty Nineteen theme.
  2. Create a new post or page using the Block Editor (Gutenberg).
  3. Add a Table block and insert some sample content.
  4. Add a caption for the table.
  5. Observe the spacing between the caption and the table in the editor.
  6. Publish the post and view it on the frontend.
  7. Notice the extra spacing between the caption and the table that was not present in the editor.

Preview:

https://rioudcpuyg.ufs.sh/f/PL8E4NiPUWyOuostJSpvbfQ5x7ZD8YW24yvhMtocPLlsne1E

Attachments (1)

Table-block-margin-WP5.3.png (54.5 KB) - added by sabernhardt 3 weeks ago.
the margin does not belong in the editor with WordPress 5.3

Download all attachments as: .zip

Change History (8)

This ticket was mentioned in PR #8559 on WordPress/wordpress-develop by @sainathpoojary.


4 weeks ago
#1

  • Keywords has-patch added

This PR addresses the issue of inconsistent spacing between the table caption and the table in the Twenty Nineteen theme. The spacing differs between the editor and the frontend.

  • Added a bottom margin to the table in the editor (style-editor.css) to match the frontend display.

Before:
https://github.com/user-attachments/assets/33718360-abb7-422b-b224-03815ddae1c6

After:
https://github.com/user-attachments/assets/265aa687-6269-49ba-a9f4-06b0b1a1e977

Trac ticket: #63143

#2 @SirLouen
4 weeks ago

  • Keywords has-testing-info added
  • Version set to 3.0

Test Report

Description

This report validates the patch works as expected with a minor caveat

Patch tested: https://github.com/WordPress/wordpress-develop/pull/8559.diff

Environment

  • WordPress: 6.8-beta2-59971-src
  • PHP: 8.2.28
  • Server: nginx/1.27.4
  • Database: mysqli (Server: 8.4.4 / Client: mysqlnd 8.2.28)
  • Browser: Chrome 134.0.0.0
  • OS: Windows 10/11
  • Theme: Twenty Nineteen 3.0
  • MU Plugins: None activated
  • Plugins:
    • Test Reports 1.2.0

Actual Results

  1. 🟠 Issue resolved with patch, but some additional review is suggested

Additional Notes

  • The frontend margin-bottom is 1rem, not 1.375rem. Not a big deal, but technically, we are looking to harmonize both views. Should we normalize the base size in the editor to 22px to get the same px with 1rem in for both results? For example by adding to set the same px standard as the front-end view.
    html {
        font-size: 22px;
    }
    
Last edited 4 weeks ago by SirLouen (previous) (diff)

#3 follow-up: @sainathpoojary
4 weeks ago

Hey @SirLouen,

I agree that normalizing the base size to 22px in the editor is a good idea. However, I was wondering would updating the base size to 22px cause any regressions in areas where styling was done assuming 16px as the base?

Looking forward to your thoughts!

@sabernhardt
3 weeks ago

the margin does not belong in the editor with WordPress 5.3

#4 in reply to: ↑ 3 @sabernhardt
3 weeks ago

  • Focuses css added
  • Version changed from 3.0 to 5.4

normalizing the base size to 22px in the editor

I do not recommend changing the base size on the html element. The theme's styles need to work even when the editor is not in an iframe. Also, calculations involving $size__spacing-unit in style-editor.scss seem to be based on 16.

The theme gave table elements a bottom margin on the front without defining the same margin in the editor. Of course, with WordPress 5.0's editor, the margin was unnecessary. The figcaption was not available until 5.4.

At least WordPress 5.3 would have an issue with the proposed margin on .wp-block-table table, but that is quite minor and the situation should be rare. The selector below would add a margin to tables that have a later sibling element, regardless of whether it is inside a Table block, but that could be over-complicated.

:where(.editor-styles-wrapper table:not(:last-child)) {
	margin-bottom: 1.375rem;
}

Also, the measurement theoretically could be 1em in the editor, which would be accurate for the default font size. However, if the table's font size is customized, it would be slightly off 1rem on the front.

The patch will need to edit style-editor.scss in addition to style-editor.css, and the spacing is different in each (indent with tab in SCSS, or two spaces in CSS).

#5 follow-up: @SirLouen
3 weeks ago

  • Keywords changes-requested added; has-patch removed

I think the @sabernhardt suggestion is accurate. Anyway, it's near impossible that a site in 5.X would be willing to specifically update a theme.

I think a full review is needed to see if there could be adaptability to 22px as the theme main file:
https://github.com/WordPress/wordpress-develop/blob/50bb23e860da86cd67e4f1d388767314bf09ea21/src/wp-content/themes/twentynineteen/style.css#L2214-L2217

@sabernhardt can you explain to me this:

The theme's styles need to work even when the editor is not in an iframe.

Where is style-editor.css being used apart from the iframe? I thought that this files were ad-hoc made for compatibility with these iframes.

@sainathpoojary regardless what you end choosing to do, don't forget, as Stephen said, to also add the edits to the SCSS file!

#6 in reply to: ↑ 5 ; follow-up: @sabernhardt
3 weeks ago

Where is style-editor.css being used apart from the iframe?

Widgets are not in an iframe even now. The post editor was not in an iframe until WordPress 6.3, and it still was not framed with certain plugins or with the Custom Fields panel after 6.3.

it's near impossible that a site in 5.X would be willing to specifically update a theme.

It should be uncommon, but Twenty Nineteen only requires 4.7.

I think a full review is needed to see if there could be adaptability to 22px

That is unnecessary to fix the table/figcaption bug for this ticket, and a full review—with refactoring—would be a large project for a six-year-old 'classic' theme.

#7 in reply to: ↑ 6 @SirLouen
3 weeks ago

Replying to sabernhardt:

Where is style-editor.css being used apart from the iframe?

Widgets are not in an iframe even now.

True, I completely forgot about Widgets editor. They should definitely be revamped. There should be a 1:1 in classic themes stylesheets.

would be a large project for a six-year-old 'classic' theme.

True, plus I've been digging a little further and I see that styles are completely inconsistent among both versions.

For example, these two styles are exactly the other way around. The bigger margins are being placed in the style that already has bigger margins.

style.css:

.entry .entry-content .wp-block-pullquote blockquote {
  border: none;
  margin-top: calc(4 * 1rem);
  margin-bottom: calc(4.33 * 1rem);
  margin-right: 0;
  padding-left: 0;
}

style-editor.css:

.wp-block-pullquote blockquote {
  margin-top: calc(3 * 1rem);
  margin-bottom: calc(3.33 * 1rem);
  hyphens: auto;
  word-break: break-word;
}

}}}

So my conclusion is: Whatever you set, it will be right.

Note: See TracTickets for help on using tickets.