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

feat: Same height columns

This commit is contained in:
Phuoc Nguyen
2022-09-21 13:22:25 +07:00
parent 0482cc69f0
commit 8fd823a570
7 changed files with 92 additions and 193 deletions

View File

@@ -0,0 +1,9 @@
<div class="same-height-columns">
{% for i in range(0, 3) -%}
<div class="same-height-columns__column">
{% rectangle "hor", "md", 100 %}
<div class="same-height-columns__content">{% lines "hor", (i + 1) * 4 %}</div>
{% rectangle "hor" %}
</div>
{%- endfor %}
</div>

View File

@@ -112,6 +112,7 @@ eleventyExcludeFromCollections: true
{% 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 %}
{% pattern "Same height columns" %}{% include "patterns/same-height-columns.njk" %}{% endpattern %}
</div>
</div>

View File

@@ -0,0 +1,54 @@
---
layout: layouts/post.njk
title: Same height columns
description: Create same height columns with CSS flexbox
keywords: css flexbox, css layout, css same height columns
---
## HTML
```html
<div class="same-height-columns">
<!-- Column -->
<div class="same-height-columns__column">
<!-- Cover -->
...
<!-- Content -->
<div class="same-height-columns__content">
...
</div>
<!-- Button sticks to the bottom -->
...
</div>
<!-- Repeat with other columns -->
...
</div>
```
## CSS
```css
.same-height-columns {
display: flex;
}
.same-height-columns__column {
flex: 1;
/* Space between columns */
margin: 0 8px;
/* Layout each column */
display: flex;
flex-direction: column;
}
.same-height-columns__content {
/* Take available height */
flex: 1;
}
```
{% demo %}{% include "patterns/same-height-columns.njk" %}{% enddemo %}

View File

@@ -1,139 +0,0 @@
import * as React from 'react';
import Head from 'next/head';
import { Pattern } from '../../constants/Pattern';
import { PatternLayout } from '../../layouts/PatternLayout';
import Block from '../../placeholders/Block';
import BrowserFrame from '../../placeholders/BrowserFrame';
import Rectangle from '../../placeholders/Rectangle';
const Details: React.FC<{}> = () => {
return (
<PatternLayout pattern={Pattern.SameHeightColumns}>
<Head>
<meta name="description" content="Create same height columns with CSS flexbox" />
<meta name="og:description" content="Create same height columns with CSS flexbox" />
<meta name="twitter:description" content="Create same height columns with CSS flexbox" />
<meta name="keywords" content="css flexbox, css layout, css same height columns" />
</Head>
<BrowserFrame
html={`
<div class="container">
<!-- Column -->
<div class="container__column">
<!-- Cover -->
...
<!-- Content -->
<div class="container__content">
...
</div>
<!-- Button sticks to the bottom -->
...
</div>
<!-- Repeat with other columns -->
...
</div>
`}
css={`
.container {
display: flex;
}
.container__column {
flex: 1;
/* Space between columns */
margin: 0 8px;
/* Layout each column */
display: flex;
flex-direction: column;
}
.container__content {
/* Take available height */
flex: 1;
}
`}
>
<div
style={{
alignItems: 'center',
display: 'flex',
flexDirection: 'column',
height: '100%',
justifyContent: 'center',
padding: '8px',
}}
>
<div style={{ display: 'flex', height: '100%', width: '100%' }}>
<div
style={{
border: '1px solid rgba(0, 0, 0, 0.2)',
borderRadius: '4px',
display: 'flex',
flex: 1,
flexDirection: 'column',
margin: '0 8px',
}}
>
<Rectangle height={200} />
<div style={{ flex: 1, padding: '16px' }}>
<Block numberOfBlocks={10} />
</div>
<div style={{ padding: '16px', width: '128px' }}>
<Rectangle height={32} />
</div>
</div>
<div
style={{
border: '1px solid rgba(0, 0, 0, 0.2)',
borderRadius: '4px',
display: 'flex',
flex: 1,
flexDirection: 'column',
margin: '0 8px',
}}
>
<Rectangle height={200} />
<div style={{ flex: 1, padding: '16px' }}>
<div style={{ marginBottom: '16px' }}>
<Block numberOfBlocks={15} />
</div>
<Block numberOfBlocks={5} />
</div>
<div style={{ padding: '16px', width: '128px' }}>
<Rectangle height={32} />
</div>
</div>
<div
style={{
border: '1px solid rgba(0, 0, 0, 0.2)',
borderRadius: '4px',
display: 'flex',
flex: 1,
flexDirection: 'column',
margin: '0 8px',
}}
>
<Rectangle height={200} />
<div style={{ flex: 1, padding: '16px' }}>
<div style={{ marginBottom: '16px' }}>
<Block numberOfBlocks={5} />
</div>
<Block numberOfBlocks={10} />
</div>
<div style={{ padding: '16px', width: '128px' }}>
<Rectangle height={32} />
</div>
</div>
</div>
</div>
</BrowserFrame>
</PatternLayout>
);
};
export default Details;

View File

@@ -1,54 +0,0 @@
import * as React from 'react';
import Frame from '../../placeholders/Frame';
import Line from '../../placeholders/Line';
import Square from '../../placeholders/Square';
const Cover: React.FC<{}> = () => {
return (
<Frame>
<div style={{ display: 'flex', height: '100%', padding: '8px' }}>
<div style={{ flex: 1, margin: '0 4px' }}>
<div style={{ height: '32px', marginBottom: '4px', width: '32px' }}>
<Square />
</div>
<div style={{ marginBottom: '4px', width: '100%' }}>
<Line />
</div>
<div style={{ marginBottom: '4px', width: '100%' }}>
<Line />
</div>
<div style={{ marginBottom: '4px', width: '80%' }}>
<Line />
</div>
<div style={{ width: '60%' }}>
<Line />
</div>
</div>
<div style={{ flex: 1, margin: '0 4px' }}>
<div style={{ height: '32px', marginBottom: '4px', width: '32px' }}>
<Square />
</div>
<div style={{ marginBottom: '4px', width: '100%' }}>
<Line />
</div>
<div style={{ marginBottom: '4px', width: '80%' }}>
<Line />
</div>
<div style={{ marginBottom: '8px', width: '60%' }}>
<Line />
</div>
<div style={{ marginBottom: '4px', width: '100%' }}>
<Line />
</div>
<div style={{ width: '60%' }}>
<Line />
</div>
</div>
</div>
</Frame>
);
};
export default Cover;

View File

@@ -67,6 +67,7 @@
@import './patterns/rating';
@import './patterns/resizable-element';
@import './patterns/ribbon';
@import './patterns/same-height-columns';
@import './patterns/search-box';
@import './patterns/separator';
@import './patterns/slider';

View File

@@ -0,0 +1,27 @@
.same-height-columns {
display: flex;
/* Demo */
width: 100%;
height: 100%;
}
.same-height-columns__column {
flex: 1;
/* Space between columns */
margin: 0 0.25rem;
/* Layout each column */
display: flex;
flex-direction: column;
/* Demo */
border: 1px solid #d1d5db;
border-radius: 0.25rem;
padding: 0.25rem;
}
.same-height-columns__content {
/* Take available height */
flex: 1;
}