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:
13
contents/_includes/patterns/masonry-grid.njk
Normal file
13
contents/_includes/patterns/masonry-grid.njk
Normal 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>
|
@@ -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
36
contents/masonry-grid.md
Normal 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 %}
|
Reference in New Issue
Block a user