Webflow Layout Techniques

Hide Collection List on Empty, or Item Qty

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

Sometimes you want your collection list to appear only if it has the right number of list items;

  • Contains at least one item
  • Contains at least X items
  • Contains no more than X items
  • Contains a specific number of items, e.g. 3

Sometimes, you even want an entire list-containing area of your layout to hide/show depending on the item count of that list.

Yes, you can, and it can all be done purely with CSS.

IMPORTANT: as @webdev notes in the Webflow forums, as of Jan-2023 the :has CSS pseudoselector has about 80% coverage in browsers and is not yet implemented by Firefox.
If 100% coverage is important to you, you may need to use a script based approach to this rather than the CSS one recommended here.

Examples

For all examples, let's assign that list or list-containing DIV an ID of listArea.

Add the custom code to your page or site /head area, or to an HTML Embed if you want it to take effect in the designer as well.

Show if at least one item

Collection Lists have the ability to show alternate content when they are empty, and you can make this alternate element blank. But what if you want to hide the entire section containing that list?

<style>
#listArea:not(:has(.w-dyn-item)) {
  display: none;   
}
</style>

Show if the item count is exactly X

You want the whole thing to appear only if there are X collection list items, and to disappear of there are more, or less than that.

<style>
#listArea:not(:has(.w-dyn-item)) {
  display: none;   
}
</style>
NOTE: change 3 in the code to the exact number of items you want.

Show if the item count is less than X

<style>
#listArea:has(.w-dyn-item:nth-last-child(3)) {
   display: none;
}
</style>
NOTE: change 3 in the code to the maximum number of items you want, plus 1.

Show if the item count is more than X

<style>
#listArea:not(:has(.w-dyn-item:nth-last-child(3))) {
  display: none;
}
</style>
NOTE: change 3 in the code to the minimum number of items you want.

References

https://css-tricks.com/solved-with-css-logical-styling-based-on-the-number-of-given-elements/

Table of Contents
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.