Webflow Layout Techniques

Variable Grid Layouts, based on Item Count

Overview
Responsive Layout Techniques
102
Element Layouts
Aspect Ratio
201
Responsive Image Annotations
6:50
202
Collection List Alternating Item Layouts
4:32
601
Collection Page & Collection List Layouts
Collection List Card Layouts
4:32
601
Creating Variable Layout Options, per Collection Item
11:46
602
Random List Items on Every Page Refresh
10:00
603
Variable Collection Item Sizes in a Grid Layout
603
Limit Collection List Items by Breakpoint
10:00
604
Hide Collection List on Empty, or Item Qty
605
Responsive Pagination
605
Masonry Grid Layouts
607
Glossary w/ Letter Groupings
612
Comparison Grid Layout
612
CMS Style Multiref-Matched Items
11:00
614
Master-Detail Layouts
Master-Detail Layouts
710
CMS-Driven Expando
19:42
714
Special Layouts
Creating Leader Lines
5:54
821
Photo Gallery Layouts
821
Column Layouts
822
Text Layouts
823
Checkerboard Grid Styling
824
Variable Grid Layouts, based on Item Count
824
Tetris Grid Layouts
12:00
826
Advanced Techniques
Breakpoints
901
Printable Layouts
903
No items found.
Published
March 26, 2025
Updated
in lightbox

Need to vary the way items span your grid, depending on the total number of items being shown?

In Webflow, the number of items in a collection list can vary based on;

  • User edits to the data
  • Time-based filtering rules, e.g. an upcoming events list filter that shows items "between today and today + 1".

In some cases you may want a layout that can dynamically respond to this situation. If there is 1 item, fill the grid. If there are 2, create two columns, and so on.

For example;

In Webflow, you can achieve this using a grid layout with pure CSS to adjust the item rowspan and colspan.

The advantage to using pure CSS is that this will work inside of the designer as well.

Demonstration

Here's a demo of this technique in action;

https://layout-demos.webflow.io/variable-grid-item-layout

Cloneable;

https://webflow.com/made-in-webflow/website/layout-demos

Setup

Here’s a custom CSS approach for the above example. Adapt this technique to your specific layout and needs.

  • Setup your collection list, limit to 3 items.
  • Set the collection list element ( middle one ) to a 2x2 grid.
  • Change the class name to grid, for this example
  • Do not span any cols or rows on the items in the designer, leave them all at the default 1x1, the CSS will do the rest

Drop an Embed element on the page with this CSS style;

<style>
/* 1 element = 2 x 2 */
.grid:has(:nth-child(1):nth-last-child(1)) > * {
  grid-column: span 2;
  grid-row: span 2;
}

/* 2 elements = 1 x 2 each */
.grid:has(:nth-child(2):nth-last-child(1)) > * {
  grid-column: span 1;
  grid-row: span 2;
}

/* 3 elements: 1 x 2 for first */
.grid:has(:nth-child(3):nth-last-child(1)) > * {
  grid-column: span 1;
  grid-row: span 1;
}
.grid:has(:nth-child(3):nth-last-child(1)) > :nth-child(1) {
  grid-column: span 1;
  grid-row: span 2;
}
</style>

The “magic” is in the selector construction, e.g.;

.grid:has(:nth-child(3):nth-last-child(1))

This applies only when “the 3rd child is the last child”, so we know we have 3 children exactly on this element.

Best Practices

Consider responsiveness.

In the CSS, you can use media queries so that you have different layout rules for different breakpoints.

Notes

https://discourse.webflow.com/t/changing-the-design-based-on-the-number-of-cms-items/316130

https://app.excalidraw.com/s/2nMbE9Ldh7X/9TFdFk9vL

FAQs

Answers to frequently asked questions.

Videos
No items found.
Table of Contents
Comments
Did we just make your life better?
Passion drives our long hours and late nights supporting the Webflow community. Click the button to show your love.