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

feat: Card layout

This commit is contained in:
Phuoc Nguyen
2022-09-21 12:35:13 +07:00
parent 344a4aeca0
commit 92ff05cd4f
7 changed files with 80 additions and 127 deletions

View File

@@ -0,0 +1,5 @@
<div class="card-layout">
{% for i in range(0, 9) -%}
<div class="card-layout__item">{% rectangle "hor", "md", 100 %}</div>
{%- endfor %}
</div>

44
contents/card-layout.md Normal file
View File

@@ -0,0 +1,44 @@
---
layout: layouts/post.njk
title: Card layout
description: Create a card layout with CSS flexbox
keywords: css card layout, css flexbox, css layout
---
## HTML
```html
<div class="card-layout">
<!-- A card with given width -->
<div class="card-layout__item">
...
</div>
<!-- Repeat other cards -->
...
</div>
```
## CSS
```css
.card-layout {
display: flex;
/* Put a card in the next row when previous cards take all width */
flex-wrap: wrap;
margin-left: -0.25rem;
margin-right: -0.25rem;
}
.card-layout__item {
/* There will be 3 cards per row */
flex-basis: 33.33333%;
padding-left: 0.25rem;
padding-right: 0.25rem;
}
```
{% demo %}{% include "patterns/card-layout.njk" %}{% enddemo %}

View File

@@ -106,5 +106,12 @@ eleventyExcludeFromCollections: true
</div>
</div>
<div class="category">
<h2 class="category__name">Layout</h2>
<div class="category__posts">
{% pattern "Card layout" %}{% include "patterns/card-layout.njk" %}{% endpattern %}
</div>
</div>
{% include "follow.njk" %}
</div>

View File

@@ -1,92 +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.CardLayout}>
<Head>
<meta name="description" content="Create a card layout with CSS flexbox" />
<meta name="og:description" content="Create a card layout with CSS flexbox" />
<meta name="twitter:description" content="Create a card layout with CSS flexbox" />
<meta name="keywords" content="css card layout, css flexbox, css layout" />
</Head>
<BrowserFrame
html={`
<div class="cards">
<!-- A card with given width -->
<div class="cards__item">
...
</div>
<!-- Repeat other cards -->
...
</div>
`}
css={`
.cards {
display: flex;
/* Put a card in the next row when previous cards take all width */
flex-wrap: wrap;
margin-left: -8px;
margin-right: -8px;
}
.cards__item {
/* There will be 4 cards per row */
flex-basis: 25%;
padding-left: 8px;
padding-right: 8px;
}
`}
>
<div
style={{
alignItems: 'center',
display: 'flex',
flexDirection: 'column',
height: '100%',
justifyContent: 'center',
padding: '8px',
}}
>
<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>
</div>
</BrowserFrame>
<Spacer size="extraLarge" />
<RelatedPatterns patterns={[Pattern.Card, Pattern.MasonryGrid, Pattern.SimpleGrid]} />
</PatternLayout>
);
};
export default Details;

View File

@@ -1,35 +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: '8px',
}}
>
<div style={{ display: 'flex', flexWrap: 'wrap', width: '100%' }}>
{Array(9)
.fill(0)
.map((_, index) => {
return (
<div key={index} style={{ flexBasis: '33%', padding: '4px' }}>
<Rectangle height={20} />
</div>
);
})}
</div>
</div>
</Frame>
);
};
export default Cover;

View File

@@ -17,6 +17,7 @@
@import './patterns/avatar-list';
@import './patterns/badge';
@import './patterns/button-with-icon';
@import './patterns/card-layout';
@import './patterns/card';
@import './patterns/centering';
@import './patterns/chip';

View File

@@ -0,0 +1,23 @@
.card-layout {
display: flex;
/* Put a card in the next row when previous cards take all width */
flex-wrap: wrap;
margin-left: -0.25rem;
margin-right: -0.25rem;
/* Demo */
width: 8rem;
}
.card-layout__item {
/* There will be 3 cards per row */
flex-basis: 33.33333%;
padding-left: 0.25rem;
padding-right: 0.25rem;
/* Demo */
margin: 0.25rem 0;
}