masonry

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Components: Masonry Layout

组件:Masonry Layout

Guides masonry layout design for content with varying heights. Masonry stacks items in columns without distinct rows; items fill gaps like a brick wall. Best for image galleries, portfolios, and discovery-focused platforms.
When invoking: On first use, if helpful, open with 1–2 sentences on what this skill covers and why it matters, then provide the main output. On subsequent use or when the user asks to skip, go directly to the main output.
用于指导高度不一的内容的Masonry布局设计。Masonry会将元素按列堆叠,没有明确的行划分,元素会像砖墙一样填补空隙,最适合图片画廊、作品集和侧重内容发现的平台。
调用时:首次使用时,如果有帮助,可以先用1-2句话说明该技能覆盖的内容及其重要性,再提供核心输出。如果是后续调用或者用户要求跳过说明,请直接输出核心内容。

When to Use Masonry

何时使用Masonry

Use masonry whenUse grid when
Varying heightsEqual-height items
Image-heavy; varied aspect ratiosProducts, templates (consistent)
Gallery, portfolio, showcaseCard grid
Discovery, browsing; visual-firstStructured browsing
See grid for equal-height grid; card for card structure.
以下场景使用Masonry以下场景使用Grid
内容高度不一元素高度一致
图片占比高、宽高比多样产品、模板类一致性内容
画廊、作品集、展示页卡片网格
内容发现、浏览场景,视觉优先结构化浏览场景
等高网格相关内容可参考grid,卡片结构相关内容可参考card

Masonry vs Grid vs Bento vs Carousel

Masonry、Grid、Bento、Carousel对比

LayoutStructureBest for
GridEqual rows and columns; uniform itemsProducts, templates, features
MasonryColumns; items stack without rows; gaps filledPinterest, Behance; varied content
BentoIntentional sections; predefined sizesHomepage, dashboard; Apple-style
CarouselSlides; one/few visible; swipe/clickTestimonials, logos, featured items; see carousel
布局结构适用场景
Grid行列均等,元素尺寸统一产品、模板、功能模块展示
Masonry按列排布,元素无行约束,自动填补空隙Pinterest、Behance类内容多样的平台
Bento板块划分明确,尺寸预定义首页、仪表盘,苹果风格设计
Carousel幻灯片形式,单次展示1/多个内容,支持滑动/点击切换testimonials、logo墙、精选内容展示,相关内容可参考carousel

Masonry Structure

Masonry结构

ElementPurpose
Columns2–4 columns; fluid or fixed
ItemsVarying heights; natural aspect ratio
GapConsistent horizontal and vertical spacing
OrderTop-to-bottom fill within columns
元素作用
2-4列,支持自适应或固定宽度
元素高度不一,保留原生宽高比
间距水平和垂直间距保持一致
排序列内按从上到下的顺序填充

Implementation

实现方式

  • CSS columns:
    column-count
    ; simple, no JS; but items flow top-to-bottom then next column
  • Masonry.js / libraries: True masonry (left-to-right fill); may need JS
  • CSS Grid +
    grid-auto-flow: dense
    : Approximate; no JS; see grid for dense grid
Note: Pure masonry can create accessibility challenges (screen reader order); ensure logical DOM order.
  • CSS columns:使用
    column-count
    属性,实现简单无需JS,但元素按列从上到下排列,排满一列再进入下一列
  • Masonry.js / 相关库:实现真正的瀑布流(从左到右填充),通常需要JS支持
  • CSS Grid +
    grid-auto-flow: dense
    :近似实现瀑布流效果,无需JS,稠密网格相关内容可参考grid
注意:纯Masonry布局可能存在无障碍问题(屏幕阅读器读取顺序异常),请确保DOM顺序符合逻辑。

SEO Considerations

SEO注意事项

Masonry + infinite scroll = content not crawlable. Masonry galleries often use infinite scroll or lazy load; crawlers cannot emulate scroll or "Load more" clicks, so content beyond the initial view is not discoverable.
If you useThen
Infinite scrollProvide paginated component pages with full URLs; implement pushState; see site-crawlability for search-friendly infinite scroll
Lazy loadEnsure content exists in HTML or is reachable via crawlable links
PaginationPrefer for SEO-critical content; crawlers can follow next/prev links
Masonry + 无限滚动 = 内容无法被爬取。 Masonry画廊通常使用无限滚动或懒加载,爬虫无法模拟滚动或“加载更多”点击操作,因此首屏之外的内容无法被抓取发现。
如果你使用对应处理方式
无限滚动提供带完整URL的分页组件页面,实现pushState;搜索友好的无限滚动实现可参考site-crawlability
懒加载确保内容存在于HTML中,或者可以通过可爬取的链接访问到
分页SEO关键内容优先使用分页,爬虫可以跟随next/prev链接爬取

Best Practices

最佳实践

PrinciplePractice
Visual-firstThumbnails; minimal text
Aspect ratioPreserve original; avoid forced cropping
Lazy loadMany images; load on scroll
PerformanceMasonry can be heavy; consider grid for simpler cases
原则实践方式
视觉优先使用缩略图,最小化文本内容
宽高比保留原始宽高比,避免强制裁剪
懒加载图片量多时开启懒加载,滚动时再加载资源
性能Masonry布局性能开销较高,简单场景可考虑使用Grid

Use Cases

适用场景

Use caseFormatPage Skill
Showcase / GalleryUser work; varied sizesshowcase-page-generator
PortfolioProjects; mixed media
Pinterest-stylePins; discovery
Image-heavy blogBlog with varied imagesblog-page-generator
场景形式关联页面技能
展示页/画廊用户作品、尺寸多样的内容showcase-page-generator
作品集项目、混合媒体内容
Pinterest风格页面Pin内容、发现类场景
图片占比高的博客图片样式多样的博客blog-page-generator

Related Skills

相关技能

  • site-crawlability: Infinite scroll SEO; paginated component pages; search-friendly implementation
  • grid: Equal-height grid; when masonry is overkill
  • carousel: Carousel for slides/rotation; when masonry is overkill
  • card: Card structure; masonry often uses cards
  • showcase-page-generator: Gallery masonry
  • image-optimization: Lazy load, aspect ratio, LCP
  • site-crawlability:无限滚动SEO、分页组件页面、搜索友好实现
  • grid:等高网格,Masonry过度设计时的替代方案
  • carousel:幻灯片/轮播布局,Masonry过度设计时的替代方案
  • card:卡片结构,Masonry布局通常使用卡片作为元素载体
  • showcase-page-generator:画廊类Masonry布局
  • image-optimization:懒加载、宽高比处理、LCP优化