How can I build a real masonry layout (Pinterest layout) using Webflow and pure CSS without falling for the ineffective CSS columns hacks?

TL;DR
  • Set up a CMS collection and add a Grid element on the page for the masonry layout.
  • Adjust Grid settings to auto-size columns and rows using CSS auto-fit/auto-fill to adapt to content.
  • Assign classes to grid items for styling, allowing them to span multiple rows/columns as needed, and adjust gap/alignment.
  • Use custom CSS to further control grid item behavior, such as grid-row for row spanning.
  • Test and adjust responsiveness across devices using Webflow's preview feature.

Creating a masonry layout, like the Pinterest style, in Webflow can be accomplished using CSS Grid rather than relying on the less-effective CSS columns trick.

1. Set Up the Webflow Structure

  • Create a Collection: If you're using CMS, set up a collection that contains the items you wish to display in the masonry layout.
  • Add a Grid Element: On your page, add a Grid element where you want the masonry layout to appear.

2. Configure CSS Grid

  • Adjust Grid Settings: Go to the Grid settings. Set the desired number of columns and rows to 'Auto' to enable automatic sizing based on the content.
  • Enable Auto-fit/Auto-fill: Use CSS auto-fit or auto-fill properties to allow the grid to adjust as items are added or resized.

3. Assign Classes and Styles

  • Apply a Class to Grid Items: Assign a class to the grid items to manage their styling. Ensure each item can span multiple rows or columns if needed.
  • Adjust Gap and Alignment: Set grid gaps for consistent spacing between items. Alignment settings can ensure items align as desired, vertically and horizontally.

4. Use Custom CSS

  • Open Custom Code Panel: Use the custom code panel in Webflow to enhance your layout further.
  • Input CSS Rules:
  • Target grid items with grid-row properties to control how rows fill the space.
  • Example: grid-row: span <number>; to specify how many rows an item should span.

5. Test Responsiveness

  • Preview and Adjust: Use Webflow’s preview feature to ensure the layout responds well across different screen sizes. Make adjustments in Grid settings for different device views if necessary.

Summary

Achieving a true masonry layout in Webflow is best done with CSS Grid. Set up a grid structure, apply the appropriate CSS properties, and ensure responsiveness by testing across various breakpoints. Avoid ineffective CSS column tricks and use custom code if needed for precise control over the grid items' behavior.

Rate this answer

Other Webflow Questions