Skip to content

Docs: restore the gutters in the Masonry example - #43449

Open
vladosskins178 wants to merge 1 commit into
twbs:mainfrom
vladosskins178:docs/masonry-gap-gutter
Open

vladosskins178 wants to merge 1 commit into
twbs:mainfrom
vladosskins178:docs/masonry-gap-gutter

Conversation

@vladosskins178

@vladosskins178 vladosskins178 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Description

The Masonry example lost its horizontal gutters after the switch to native gap gutters (#43282). Masonry positions the columns absolutely, so the row's gap does not apply to them. It places each column one column width after the previous one, so the cards touch. The last column also ends two gutters short of the row (48px at 1400px wide).

This gives Masonry a gutter sizer: an empty .masonry-gutter element with style="width: var(--bs-gutter-x)", passed as Masonry's gutter option, with itemSelector limited to the other children of the row. The column widths already account for the gap ((100% + gap) * n - gap), so column width plus gutter matches the grid exactly. The intro paragraph shows the new options and explains why the sizer is needed.

Motivation & Context

Fixes #43448.

I tested it in headless Chrome. I compiled scss/bootstrap.scss from main and ran the build's PostCSS config to get the --bs- prefix. Then I rendered the example's markup with Masonry 4.2.2 (the same CDN file and SRI hash) and measured the card positions:

viewport before: column lefts / gap / right edge after
1400 (3 cols) 112, 488, 864 / 0px / 1240 of 1288 112, 512, 912 / 24px / 1288 of 1288
900 (2 cols) 102, 438 / 0px / 774 of 798 102, 462 / 24px / 798 of 798
500 (1 col) unchanged unchanged

Resizing a loaded page (1400 → 900 → 500 → 1200) re-lays the cards out with the same 24px gutters. A note on the selector: Masonry's itemSelector also matches descendants of the children. A plain :not(.masonry-gutter) would turn every element inside the cards into an item, so it is scoped with .row >.

Type of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring (non-breaking change)
  • Breaking change (fix or feature that would change existing functionality)

Checklist

  • I have read the contributing guidelines
  • My code follows the code style of the project (using npm run lint) (markup-only change in one example; inline styles are allowed by the html-validate config)
  • My change introduces changes to the documentation
  • I have updated the documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed

Live previews

Related issues

#43448, #43282

Since the grid uses native gap gutters (twbs#43282), Masonry's absolute
positioning ignores the row gap, so the cards touched and the last
column ended two gutters short of the row. Give Masonry a gutter sizer
as wide as --bs-gutter-x and limit its items to the row's columns.
@julien-deramond julien-deramond added v6 v6, the main branch bug Something does not work as documented docs Documentation site and its content examples The examples in the docs html Component markup: elements, attributes, structure labels Nov 23, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something does not work as documented docs Documentation site and its content examples The examples in the docs html Component markup: elements, attributes, structure v6 v6, the main branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Masonry.js has stopped working since the latest grid changes

2 participants