When using a mobile-first breakpoint configuration, Heading, Paragraph and Fallback Spacing are not applied to custom CSS selectors defined under Theme Styles → Contextual Spacing → Apply Spacing Inside.
Contextual Spacing works correctly for regular WordPress post content. Additional Target Elements also work as expected within custom selectors.
Steps to reproduce
- Configure Bricks to use mobile-first breakpoints.
- Open Theme Styles → Contextual Spacing.
- Set values for Heading, Paragraph and Fallback Spacing at the base breakpoint (Mobile Portrait).
- Enter
.prosein the Apply Spacing Inside field. - Add a Container element and assign the class
prose. - Set the container’s row gap to
0. - Add several Heading and Basic Text elements, using
pas the HTML tag for Basic Text. - Inspect the result and the generated CSS in the frontend.
Expected behavior
Heading, Paragraph and Fallback Spacing should be applied within .prose, respecting the configured breakpoint values.
Actual behavior
No corresponding CSS rules are generated for .prose. Rules for Additional Target Elements, however, are generated correctly.
Root cause
I investigated the source code of Bricks and found that the implementation in includes/assets.php, lines 4812–4851, within generate_inline_css_from_element(), retrieves the spacing values without considering breakpoint suffixes:
$heading_spacing = isset( $settings['contextualSpacingHeading'] ) ? $settings['contextualSpacingHeading'] : '';
The same applies to contextualSpacingParagraph and contextualSpacingFallback.
With a mobile-first configuration, however, these settings are stored with the :mobile_portrait suffix, as confirmed by my Theme Style export:
"contextualSpacingHeading:mobile_portrait": "var(--heading-spacing)",
"contextualSpacingParagraph:mobile_portrait": "var(--paragraph-spacing)",
"contextualSpacingFallback:mobile_portrait": "var(--flow-spacing)",
"contextualSpacingApplyTo": ".prose"
As a result, the spacing values are not retrieved and the corresponding CSS rules are not generated.
The CSS generation for custom selectors appears to assume a desktop base breakpoint and does not account for breakpoint-specific values.
Suggested fix
Ensure that Heading, Paragraph and Fallback Spacing are correctly applied to the selectors defined under Apply Spacing Inside, taking the active base breakpoint and breakpoint-specific spacing values into account.
The existing implementation for Additional Target Elements already handles this correctly and could serve as a reference.