mirror of
https://github.com/phuoc-ng/csslayout.git
synced 2025-08-06 14:16: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">
|
<div class="category__posts">
|
||||||
{% pattern "Card layout" %}{% include "patterns/card-layout.njk" %}{% endpattern %}
|
{% pattern "Card layout" %}{% include "patterns/card-layout.njk" %}{% endpattern %}
|
||||||
{% pattern "Holy grail" %}{% include "patterns/holy-grail.njk" %}{% endpattern %}
|
{% pattern "Holy grail" %}{% include "patterns/holy-grail.njk" %}{% endpattern %}
|
||||||
|
{% pattern "Masonry grid" %}{% include "patterns/masonry-grid.njk" %}{% endpattern %}
|
||||||
</div>
|
</div>
|
||||||
</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 %}
|
@@ -1,101 +0,0 @@
|
|||||||
import * as React from 'react';
|
|
||||||
import Head from 'next/head';
|
|
||||||
import { Spacer } from '@1milligram/design';
|
|
||||||
|
|
||||||
import { RelatedPatterns } from '../../components/RelatedPatterns';
|
|
||||||
import { Pattern } from '../../constants/Pattern';
|
|
||||||
import { PatternLayout } from '../../layouts/PatternLayout';
|
|
||||||
import BrowserFrame from '../../placeholders/BrowserFrame';
|
|
||||||
import Rectangle from '../../placeholders/Rectangle';
|
|
||||||
|
|
||||||
const Details: React.FC<{}> = () => {
|
|
||||||
return (
|
|
||||||
<PatternLayout pattern={Pattern.MasonryGrid}>
|
|
||||||
<Head>
|
|
||||||
<meta name="description" content="Create a masonry grid with CSS" />
|
|
||||||
<meta name="og:description" content="Create a masonry grid with CSS" />
|
|
||||||
<meta name="twitter:description" content="Create a masonry grid with CSS" />
|
|
||||||
<meta name="keywords" content="css column-count, css column-gap, css masonry, css masonry grid" />
|
|
||||||
</Head>
|
|
||||||
<BrowserFrame
|
|
||||||
html={`
|
|
||||||
<div class="masonry-grid">
|
|
||||||
<!--Item -->
|
|
||||||
<div class="masonry-grid__item">...</div>
|
|
||||||
|
|
||||||
<!-- Repeat other items -->
|
|
||||||
</div>
|
|
||||||
`}
|
|
||||||
css={`
|
|
||||||
.masonry-grid {
|
|
||||||
/* It is split into 3 columns */
|
|
||||||
column-count: 3;
|
|
||||||
|
|
||||||
/* The space between columns */
|
|
||||||
column-gap: 1rem;
|
|
||||||
|
|
||||||
/* Misc */
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.masonry-grid__item {
|
|
||||||
/* Prevent a column from breaking into multiple columns */
|
|
||||||
break-inside: avoid;
|
|
||||||
|
|
||||||
/* Misc */
|
|
||||||
margin-bottom: 1rem;
|
|
||||||
}
|
|
||||||
`}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
alignItems: 'center',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
height: '100%',
|
|
||||||
justifyContent: 'center',
|
|
||||||
padding: '1rem',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div className="masonry-grid">
|
|
||||||
<div className="masonry-grid__item">
|
|
||||||
<Rectangle height={32} />
|
|
||||||
</div>
|
|
||||||
<div className="masonry-grid__item">
|
|
||||||
<Rectangle height={64} />
|
|
||||||
</div>
|
|
||||||
<div className="masonry-grid__item">
|
|
||||||
<Rectangle height={96} />
|
|
||||||
</div>
|
|
||||||
<div className="masonry-grid__item">
|
|
||||||
<Rectangle height={64} />
|
|
||||||
</div>
|
|
||||||
<div className="masonry-grid__item">
|
|
||||||
<Rectangle height={128} />
|
|
||||||
</div>
|
|
||||||
<div className="masonry-grid__item">
|
|
||||||
<Rectangle height={96} />
|
|
||||||
</div>
|
|
||||||
<div className="masonry-grid__item">
|
|
||||||
<Rectangle height={128} />
|
|
||||||
</div>
|
|
||||||
<div className="masonry-grid__item">
|
|
||||||
<Rectangle height={32} />
|
|
||||||
</div>
|
|
||||||
<div className="masonry-grid__item">
|
|
||||||
<Rectangle height={64} />
|
|
||||||
</div>
|
|
||||||
<div className="masonry-grid__item">
|
|
||||||
<Rectangle height={32} />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</BrowserFrame>
|
|
||||||
|
|
||||||
<Spacer size="extraLarge" />
|
|
||||||
<RelatedPatterns patterns={[Pattern.CardLayout, Pattern.SimpleGrid]} />
|
|
||||||
</PatternLayout>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Details;
|
|
@@ -1,56 +0,0 @@
|
|||||||
import * as React from 'react';
|
|
||||||
|
|
||||||
import Frame from '../../placeholders/Frame';
|
|
||||||
import Rectangle from '../../placeholders/Rectangle';
|
|
||||||
|
|
||||||
const Cover: React.FC<{}> = () => {
|
|
||||||
return (
|
|
||||||
<Frame>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
alignItems: 'center',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
height: '100%',
|
|
||||||
justifyContent: 'center',
|
|
||||||
padding: '0.5rem',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
columnCount: 3,
|
|
||||||
columnGap: '0.25rem',
|
|
||||||
width: '80%',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div style={{ breakInside: 'avoid', marginBottom: '0.25rem' }}>
|
|
||||||
<Rectangle height={16} />
|
|
||||||
</div>
|
|
||||||
<div style={{ breakInside: 'avoid', marginBottom: '0.25rem' }}>
|
|
||||||
<Rectangle height={12} />
|
|
||||||
</div>
|
|
||||||
<div style={{ breakInside: 'avoid', marginBottom: '0.25rem' }}>
|
|
||||||
<Rectangle height={8} />
|
|
||||||
</div>
|
|
||||||
<div style={{ breakInside: 'avoid', marginBottom: '0.25rem' }}>
|
|
||||||
<Rectangle height={24} />
|
|
||||||
</div>
|
|
||||||
<div style={{ breakInside: 'avoid', marginBottom: '0.25rem' }}>
|
|
||||||
<Rectangle height={16} />
|
|
||||||
</div>
|
|
||||||
<div style={{ breakInside: 'avoid', marginBottom: '0.25rem' }}>
|
|
||||||
<Rectangle height={12} />
|
|
||||||
</div>
|
|
||||||
<div style={{ breakInside: 'avoid', marginBottom: '0.25rem' }}>
|
|
||||||
<Rectangle height={16} />
|
|
||||||
</div>
|
|
||||||
<div style={{ breakInside: 'avoid', marginBottom: '0.25rem' }}>
|
|
||||||
<Rectangle height={12} />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</Frame>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Cover;
|
|
@@ -49,6 +49,7 @@
|
|||||||
@import './patterns/keyboard-shortcut';
|
@import './patterns/keyboard-shortcut';
|
||||||
@import './patterns/layered-card';
|
@import './patterns/layered-card';
|
||||||
@import './patterns/lined-paper';
|
@import './patterns/lined-paper';
|
||||||
|
@import './patterns/masonry-grid';
|
||||||
@import './patterns/media-object';
|
@import './patterns/media-object';
|
||||||
@import './patterns/modal';
|
@import './patterns/modal';
|
||||||
@import './patterns/notification';
|
@import './patterns/notification';
|
||||||
|
19
styles/patterns/_masonry-grid.scss
Normal file
19
styles/patterns/_masonry-grid.scss
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
.masonry-grid {
|
||||||
|
/* It is split into 3 columns */
|
||||||
|
column-count: 3;
|
||||||
|
|
||||||
|
/* The space between columns */
|
||||||
|
column-gap: 1rem;
|
||||||
|
|
||||||
|
/* Demo */
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.masonry-grid__item {
|
||||||
|
/* Prevent a column from breaking into multiple columns */
|
||||||
|
break-inside: avoid;
|
||||||
|
|
||||||
|
/* Misc */
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
Reference in New Issue
Block a user