mirror of
https://github.com/phuoc-ng/csslayout.git
synced 2025-08-05 05:37:29 +02:00
Add Masonry Grid
This commit is contained in:
@@ -45,6 +45,7 @@ enum Pattern {
|
||||
KeyboardShortcut = 'Keyboard shortcut',
|
||||
LayeredCard = 'Layered card',
|
||||
LinedPaper = 'Lined paper',
|
||||
MasonryGrid = 'Masonry grid',
|
||||
MediaObject = 'Media object',
|
||||
MegaMenu = 'Mega menu',
|
||||
Menu = 'Menu',
|
||||
|
@@ -52,6 +52,7 @@ const ExplorePage = () => {
|
||||
<div className="explore__collection">
|
||||
<CoverCard pattern={Pattern.CardLayout} />
|
||||
<CoverCard pattern={Pattern.HolyGrail} />
|
||||
<CoverCard pattern={Pattern.MasonryGrid} />
|
||||
<CoverCard pattern={Pattern.SameHeightColumns} />
|
||||
<CoverCard pattern={Pattern.Sidebar} />
|
||||
<CoverCard pattern={Pattern.SimpleGrid} />
|
||||
|
@@ -21,8 +21,7 @@ const Details: React.FC<{}> = () => {
|
||||
<meta name="twitter:description" content="Create a card layout with CSS flexbox" />
|
||||
<meta name="keywords" content="css card layout, css flexbox, css layout" />
|
||||
</Helmet>
|
||||
<div className='p-8 pb-20'>
|
||||
<BrowserFrame
|
||||
<BrowserFrame
|
||||
html={`
|
||||
<div class="cards">
|
||||
<!-- A card with given width -->
|
||||
@@ -53,40 +52,39 @@ css={`
|
||||
padding-right: 8px;
|
||||
}
|
||||
`}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
alignItems: 'center',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
height: '100%',
|
||||
justifyContent: 'center',
|
||||
padding: '8px',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
alignItems: 'center',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
height: '100%',
|
||||
justifyContent: 'center',
|
||||
padding: '8px',
|
||||
flexWrap: 'wrap',
|
||||
margin: '0 -8px',
|
||||
width: '60%',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
flexWrap: 'wrap',
|
||||
margin: '0 -8px',
|
||||
width: '60%',
|
||||
}}
|
||||
>
|
||||
{
|
||||
Array(10).fill(0).map((_, index) => {
|
||||
return (
|
||||
<div key={index} style={{ flexBasis: '25%', marginBottom: '24px', padding: '0 8px' }}>
|
||||
<Rectangle height={80} />
|
||||
</div>
|
||||
);
|
||||
})
|
||||
}
|
||||
</div>
|
||||
{
|
||||
Array(10).fill(0).map((_, index) => {
|
||||
return (
|
||||
<div key={index} style={{ flexBasis: '25%', marginBottom: '24px', padding: '0 8px' }}>
|
||||
<Rectangle height={80} />
|
||||
</div>
|
||||
);
|
||||
})
|
||||
}
|
||||
</div>
|
||||
</BrowserFrame>
|
||||
</div>
|
||||
</div>
|
||||
</BrowserFrame>
|
||||
|
||||
<RelatedPatterns patterns={[Pattern.Card, Pattern.SimpleGrid]} />
|
||||
<RelatedPatterns patterns={[Pattern.Card, Pattern.MasonryGrid, Pattern.SimpleGrid]} />
|
||||
</DetailsLayout>
|
||||
);
|
||||
};
|
||||
|
45
client/patterns/masonry-grid/Cover.tsx
Normal file
45
client/patterns/masonry-grid/Cover.tsx
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* A collection of popular layouts and patterns made with CSS (https://csslayout.io)
|
||||
* (c) 2019 - 2021 Nguyen Huu Phuoc <https://twitter.com/nghuuphuoc>
|
||||
*/
|
||||
|
||||
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;
|
86
client/patterns/masonry-grid/Details.tsx
Normal file
86
client/patterns/masonry-grid/Details.tsx
Normal file
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* A collection of popular layouts and patterns made with CSS (https://csslayout.io)
|
||||
* (c) 2019 - 2021 Nguyen Huu Phuoc <https://twitter.com/nghuuphuoc>
|
||||
*/
|
||||
|
||||
import * as React from 'react';
|
||||
import { Helmet } from 'react-helmet';
|
||||
|
||||
import RelatedPatterns from '../../components/RelatedPatterns';
|
||||
import Pattern from '../../constants/Pattern';
|
||||
import DetailsLayout from '../../layouts/DetailsLayout';
|
||||
import BrowserFrame from '../../placeholders/BrowserFrame';
|
||||
import Rectangle from '../../placeholders/Rectangle';
|
||||
|
||||
import './masonry-grid.css';
|
||||
|
||||
const Details: React.FC<{}> = () => {
|
||||
return (
|
||||
<DetailsLayout pattern={Pattern.MasonryGrid}>
|
||||
<Helmet>
|
||||
<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" />
|
||||
</Helmet>
|
||||
<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>
|
||||
|
||||
<RelatedPatterns patterns={[Pattern.CardLayout, Pattern.SimpleGrid]} />
|
||||
</DetailsLayout>
|
||||
);
|
||||
};
|
||||
|
||||
export default Details;
|
20
client/patterns/masonry-grid/masonry-grid.css
Normal file
20
client/patterns/masonry-grid/masonry-grid.css
Normal file
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* A collection of popular layouts and patterns made with CSS (https://csslayout.io)
|
||||
* (c) 2019 - 2021 Nguyen Huu Phuoc <https://twitter.com/nghuuphuoc>
|
||||
*/
|
||||
|
||||
.masonry-grid {
|
||||
column-count: 3;
|
||||
column-gap: 1rem;
|
||||
|
||||
/* Misc */
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.masonry-grid__item {
|
||||
/* Prevent a column from breaking into multiple columns */
|
||||
break-inside: avoid;
|
||||
|
||||
/* Misc */
|
||||
margin-bottom: 1rem;
|
||||
}
|
@@ -21,8 +21,7 @@ const Details: React.FC<{}> = () => {
|
||||
<meta name="twitter:description" content="Create a simple grid with CSS flexbox" />
|
||||
<meta name="keywords" content="css flexbox, css flexbox grid, css grid, css layout" />
|
||||
</Helmet>
|
||||
<div className='p-8 pb-20'>
|
||||
<BrowserFrame
|
||||
<BrowserFrame
|
||||
html={`
|
||||
<!-- Row -->
|
||||
<div class="row">
|
||||
@@ -57,92 +56,91 @@ css={`
|
||||
flex: 1;
|
||||
}
|
||||
`}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
alignItems: 'center',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
height: '100%',
|
||||
justifyContent: 'center',
|
||||
padding: '8px',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
alignItems: 'center',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
height: '100%',
|
||||
justifyContent: 'center',
|
||||
padding: '8px',
|
||||
}}
|
||||
>
|
||||
<div style={{ width: '60%' }}>
|
||||
<div style={{ display: 'flex', margin: '0 -8px 8px -8px' }}>
|
||||
<div style={{ flex: '1', padding: '0 8px' }}>
|
||||
<Rectangle height={32} />
|
||||
</div>
|
||||
<div style={{ flex: '1', padding: '0 8px' }}>
|
||||
<Rectangle height={32} />
|
||||
</div>
|
||||
<div style={{ width: '60%' }}>
|
||||
<div style={{ display: 'flex', margin: '0 -8px 8px -8px' }}>
|
||||
<div style={{ flex: '1', padding: '0 8px' }}>
|
||||
<Rectangle height={32} />
|
||||
</div>
|
||||
|
||||
<div style={{ display: 'flex', margin: '0 -8px 32px -8px' }}>
|
||||
<div style={{ flex: '0 0 50%', padding: '0 8px' }}>
|
||||
<Rectangle height={32} />
|
||||
</div>
|
||||
<div style={{ flex: '1', padding: '0 8px' }}>
|
||||
<Rectangle height={32} />
|
||||
</div>
|
||||
<div style={{ flex: '1', padding: '0 8px' }}>
|
||||
<Rectangle height={32} />
|
||||
</div>
|
||||
<div style={{ flex: '1', padding: '0 8px' }}>
|
||||
<Rectangle height={32} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style={{ display: 'flex', margin: '0 -8px 8px -8px' }}>
|
||||
<div style={{ flex: '1', padding: '0 8px' }}>
|
||||
<Rectangle height={32} />
|
||||
</div>
|
||||
<div style={{ flex: '1', padding: '0 8px' }}>
|
||||
<Rectangle height={32} />
|
||||
</div>
|
||||
<div style={{ flex: '1', padding: '0 8px' }}>
|
||||
<Rectangle height={32} />
|
||||
</div>
|
||||
<div style={{ display: 'flex', margin: '0 -8px 32px -8px' }}>
|
||||
<div style={{ flex: '0 0 50%', padding: '0 8px' }}>
|
||||
<Rectangle height={32} />
|
||||
</div>
|
||||
|
||||
<div style={{ display: 'flex', margin: '0 -8px 32px -8px' }}>
|
||||
<div style={{ flex: '0 0 33.3333%', padding: '0 8px' }}>
|
||||
<Rectangle height={32} />
|
||||
</div>
|
||||
<div style={{ flex: '1', padding: '0 8px' }}>
|
||||
<Rectangle height={32} />
|
||||
</div>
|
||||
<div style={{ flex: '1', padding: '0 8px' }}>
|
||||
<Rectangle height={32} />
|
||||
</div>
|
||||
|
||||
<div style={{ display: 'flex', margin: '0 -8px 8px -8px' }}>
|
||||
<div style={{ flex: '1', padding: '0 8px' }}>
|
||||
<Rectangle height={32} />
|
||||
</div>
|
||||
<div style={{ flex: '1', padding: '0 8px' }}>
|
||||
<Rectangle height={32} />
|
||||
</div>
|
||||
<div style={{ flex: '1', padding: '0 8px' }}>
|
||||
<Rectangle height={32} />
|
||||
</div>
|
||||
<div style={{ flex: '1', padding: '0 8px' }}>
|
||||
<Rectangle height={32} />
|
||||
</div>
|
||||
<div style={{ flex: '1', padding: '0 8px' }}>
|
||||
<Rectangle height={32} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style={{ display: 'flex', margin: '0 -8px 0 -8px' }}>
|
||||
<div style={{ flex: '0 0 25%', padding: '0 8px' }}>
|
||||
<Rectangle height={32} />
|
||||
</div>
|
||||
<div style={{ flex: '1', padding: '0 8px' }}>
|
||||
<Rectangle height={32} />
|
||||
</div>
|
||||
<div style={{ flex: '0 0 33.3333%', padding: '0 8px' }}>
|
||||
<Rectangle height={32} />
|
||||
</div>
|
||||
<div style={{ display: 'flex', margin: '0 -8px 8px -8px' }}>
|
||||
<div style={{ flex: '1', padding: '0 8px' }}>
|
||||
<Rectangle height={32} />
|
||||
</div>
|
||||
<div style={{ flex: '1', padding: '0 8px' }}>
|
||||
<Rectangle height={32} />
|
||||
</div>
|
||||
<div style={{ flex: '1', padding: '0 8px' }}>
|
||||
<Rectangle height={32} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style={{ display: 'flex', margin: '0 -8px 32px -8px' }}>
|
||||
<div style={{ flex: '0 0 33.3333%', padding: '0 8px' }}>
|
||||
<Rectangle height={32} />
|
||||
</div>
|
||||
<div style={{ flex: '1', padding: '0 8px' }}>
|
||||
<Rectangle height={32} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style={{ display: 'flex', margin: '0 -8px 8px -8px' }}>
|
||||
<div style={{ flex: '1', padding: '0 8px' }}>
|
||||
<Rectangle height={32} />
|
||||
</div>
|
||||
<div style={{ flex: '1', padding: '0 8px' }}>
|
||||
<Rectangle height={32} />
|
||||
</div>
|
||||
<div style={{ flex: '1', padding: '0 8px' }}>
|
||||
<Rectangle height={32} />
|
||||
</div>
|
||||
<div style={{ flex: '1', padding: '0 8px' }}>
|
||||
<Rectangle height={32} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style={{ display: 'flex', margin: '0 -8px 0 -8px' }}>
|
||||
<div style={{ flex: '0 0 25%', padding: '0 8px' }}>
|
||||
<Rectangle height={32} />
|
||||
</div>
|
||||
<div style={{ flex: '1', padding: '0 8px' }}>
|
||||
<Rectangle height={32} />
|
||||
</div>
|
||||
<div style={{ flex: '0 0 33.3333%', padding: '0 8px' }}>
|
||||
<Rectangle height={32} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</BrowserFrame>
|
||||
</div>
|
||||
</div>
|
||||
</BrowserFrame>
|
||||
|
||||
<RelatedPatterns patterns={[Pattern.CardLayout]} />
|
||||
<RelatedPatterns patterns={[Pattern.CardLayout, Pattern.MasonryGrid]} />
|
||||
</DetailsLayout>
|
||||
);
|
||||
};
|
||||
|
Reference in New Issue
Block a user