1
0
mirror of https://github.com/phuoc-ng/csslayout.git synced 2025-08-30 09:09:50 +02:00

feat: Masonry grid

This commit is contained in:
Phuoc Nguyen
2022-09-21 13:10:55 +07:00
parent 3d74fde098
commit 0482cc69f0
7 changed files with 70 additions and 157 deletions

View File

@@ -0,0 +1,13 @@
<div class="masonry-grid">
<div class="masonry-grid__item">{% rectangle "hor", "sm", 100 %}</div>
<div class="masonry-grid__item">{% rectangle "hor", "md", 100 %}</div>
<div class="masonry-grid__item">{% rectangle "hor", "md", 100 %}</div>
<div class="masonry-grid__item">{% rectangle "hor", "sm", 100 %}</div>
<div class="masonry-grid__item">{% rectangle "hor", "sm", 100 %}</div>
<div class="masonry-grid__item">{% rectangle "hor", "sm", 100 %}</div>
<div class="masonry-grid__item">{% rectangle "hor", "md", 100 %}</div>
<div class="masonry-grid__item">{% rectangle "hor", "sm", 100 %}</div>
<div class="masonry-grid__item">{% rectangle "hor", "md", 100 %}</div>
<div class="masonry-grid__item">{% rectangle "hor", "sm", 100 %}</div>
<div class="masonry-grid__item">{% rectangle "hor", "sm", 100 %}</div>
</div>

View File

@@ -111,6 +111,7 @@ eleventyExcludeFromCollections: true
<div class="category__posts">
{% pattern "Card layout" %}{% include "patterns/card-layout.njk" %}{% endpattern %}
{% pattern "Holy grail" %}{% include "patterns/holy-grail.njk" %}{% endpattern %}
{% pattern "Masonry grid" %}{% include "patterns/masonry-grid.njk" %}{% endpattern %}
</div>
</div>

36
contents/masonry-grid.md Normal file
View File

@@ -0,0 +1,36 @@
---
layout: layouts/post.njk
title: Masonry grid
description: Create a masonry grid with CSS
keywords: css column-count, css column-gap, css masonry, css masonry grid
---
## HTML
```html
<div class="masonry-grid">
<!--Item -->
<div class="masonry-grid__item">...</div>
<!-- Repeat other items -->
</div>
```
## CSS
```css
.masonry-grid {
/* It is split into 3 columns */
column-count: 3;
/* The space between columns */
column-gap: 1rem;
}
.masonry-grid__item {
/* Prevent a column from breaking into multiple columns */
break-inside: avoid;
}
```
{% demo %}{% include "patterns/masonry-grid.njk" %}{% enddemo %}