Opened 18 months ago
Closed 17 months ago
#61845 closed defect (bug) (fixed)
Twenty Twenty: correct font-size for Code block and other preformatted elements
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 6.7 | Priority: | normal |
| Severity: | normal | Version: | 6.6.1 |
| Component: | Bundled Theme | Keywords: | needs-testing has-patch commit |
| Focuses: | css | Cc: |
Description
Hello Team,
I have checked the "Code" block and found that its font-size is not similar on editor & front-end sides.
I think that it should be same on both the sides( Editor & Front-end )
Here, I have attached its screenshots for reference.
Thanks,
Attachments (3)
Change History (11)
#1
@
18 months ago
- Keywords reporter-feedback added; needs-patch dev-feedback removed
Hi @viralsampat I see something different with the latest trunk of Twenty Twenty are you able to test using that please?
#2
@
18 months ago
@karmatosed
I tested with the latest trunk, and it seems the issue is with the units that is used for font-size: 0.9em
CSS style which is loaded on the block editor [Admin].
File: src/wp-content/themes/twentytwenty/assets/css/editor-style-block.css
328: .editor-styles-wrapper kbd,
329: .editor-styles-wrapper pre,
330: .editor-styles-wrapper samp {
331: border-radius: 0;
332: font-size: 0.75em;
333: padding: 4px 6px;
334: }
335:
CSS styles which are loaded on the frontend [Public].
File: src/wp-content/themes/twentytwenty/style.css
575: code,
576: kbd,
577: pre,
578: samp {
579: font-family: monospace;
580: font-size: 0.9em;
581: padding: 0.4rem 0.6rem;
582: }
And at the backend and frontend the <code> is wrapped by <pre> tag. So, the acutal font of the code tag depends upon the <pre> tag whose font-size will depend upon it's parent, which is different in backend and frontend.
<pre class="wp-block-code">
<code><?php echo ('Hello World'); ?></code>
</pre>
This can be fixed, if we use rem unit instead of em.
This ticket was mentioned in PR #7190 on WordPress/wordpress-develop by @brobken.
17 months ago
#3
- Keywords has-patch added
I've changed the base font size on the frontend because imho em font-size isn't preferred when the font size is defined like it is here. Hence it wasn't easy to convert this to the editor styles; this way both can font sizes can be the same.
Trac ticket: https://core.trac.wordpress.org/ticket/61845
#4
@
17 months ago
In my opinion, it shouldn't be defined on the frontend CSS with 0.9em, but rather a definition in 1.8rem.
Resulting to being rendered from 17.01 px to 18px now.
This makes it easier to have it set also in the backend editor at this size. I don't know if that's a problem? In the meantime I've submitted a possible solution.
@
17 months ago
Uses 0.9em for preformatted elements with latest WordPress, assigns 16px for older editor, adds border
#6
@
17 months ago
- Keywords reporter-feedback removed
- Summary changed from Twenty Twenty theme: The code block font-size not same on editor & front-end sides. to Twenty Twenty: correct font-size for Code block and other preformatted elements
PR 259 purposely made the font size for code elements smaller than the body text. Regular body text is 1.8rem (or 18px in the editor) on small screens and 2.1rem (21px) from 700 pixels and wider.
Setting a rem value for code and similar elements would require either 1.5 or 1.6 on small screens and about 1.8 at the 700px breakpoint. Then when someone sets a font size with block settings in the sidebar, that selection would need to override the theme's default value.
I think that keeping the 0.9em value would be better than creating new rem and px measurements, but it should be consistent.
- The Code block uses
codeinside apreelement, which causes the rule to multiply by 0.9 twice on the front end. Setting eitherpre codeor.wp-block-code codeto1emcould make it the value of0.9emcompared to thebodysize. (I prefer1eminstead ofinherit, which should work just as well.) - The elements
kbd,preandsampplus Verse blocks were set to0.75emin the editor styles at initial commit. - PR 384 introduced the
14pxand16pxsizes for blocks in the editor, and PR 890 added14pxfor preformatted text in a Classic block. - [50358] corrected the Verse block
font-sizein the editor without changing the other blocks.
- Sets
1emfont size forcodeelements inside apre, both on the front and in the editor, to match the0.9emsize of thepreelement. - Corrects
0.75emvalue in editor to0.9emfor preformatted elements. - Retains the pixel-based font size for Classic blocks in the non-framed editor and outdated selectors (backward compatibility), but uses the closer
16pxat any screen size. - Retains the
0.9emruleset for the Verse block, though it would be unnecessary with the proposed.editor-styles-wrapper preselector and the latest WordPress. (If that ruleset is removed in another patch, the block would fall back to 16px with older WordPress.) - Adds the border and padding in the editor for
preelements, and the Code block has the same styles on.wp-block-codefor older WordPress versions that used adiv.
Back-end