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

feat: Simple grid

This commit is contained in:
Phuoc Nguyen
2022-09-21 13:45:37 +07:00
parent b49ac2a911
commit f016b79765
7 changed files with 103 additions and 201 deletions

View File

@@ -0,0 +1,15 @@
<div class="simple-grid">
<div class="simple-grid__cell simple-grid__cell--1/4">{% rectangle "hor", "md", 100 %}</div>
<div class="simple-grid__cell simple-grid__cell--fill">{% rectangle "hor", "md", 100 %}</div>
</div>
<div class="simple-grid">
<div class="simple-grid__cell simple-grid__cell--1/3">{% rectangle "hor", "md", 100 %}</div>
<div class="simple-grid__cell simple-grid__cell--1/3">{% rectangle "hor", "md", 100 %}</div>
<div class="simple-grid__cell simple-grid__cell--1/3">{% rectangle "hor", "md", 100 %}</div>
</div>
<div class="simple-grid">
<div class="simple-grid__cell simple-grid__cell--1/4">{% rectangle "hor", "md", 100 %}</div>
<div class="simple-grid__cell simple-grid__cell--1/4">{% rectangle "hor", "md", 100 %}</div>
<div class="simple-grid__cell simple-grid__cell--1/4">{% rectangle "hor", "md", 100 %}</div>
<div class="simple-grid__cell simple-grid__cell--1/4">{% rectangle "hor", "md", 100 %}</div>
</div>

View File

@@ -114,6 +114,7 @@ eleventyExcludeFromCollections: true
{% pattern "Masonry grid" %}{% include "patterns/masonry-grid.njk" %}{% endpattern %}
{% pattern "Same height columns" %}{% include "patterns/same-height-columns.njk" %}{% endpattern %}
{% pattern "Sidebar" %}{% include "patterns/sidebar.njk" %}{% endpattern %}
{% pattern "Simple grid" %}{% include "patterns/simple-grid.njk" %}{% endpattern %}
</div>
</div>

54
contents/simple-grid.md Normal file
View File

@@ -0,0 +1,54 @@
---
layout: layouts/post.njk
title: Simple grid
description: Create a simple grid with CSS flexbox
keywords: css flexbox, css flexbox grid, css grid, css layout
---
## HTML
```html
<!-- Row -->
<div class="simple-grid">
<!--Cell with given width. Replace 25% with whatever you want -->
<div class="simple-grid__cell simple-grid__cell--1/4">25%</div>
<!-- Cell that takes remaining width -->
<div class="simple-grid__cell simple-grid__cell--fill">
...
</div>
</div>
```
## CSS
```css
.simple-grid {
display: flex;
margin-left: -0.25rem;
margin-right: -0.25rem;
}
.simple-grid__cell {
padding-left: 0.25rem;
padding-right: 0.25rem;
}
.simple-grid__cell--fill {
flex: 1;
}
/* Cell with given width */
.simple-grid__cell--1\/2 {
flex: 0 0 50%;
}
.simple-grid__cell--1\/3 {
flex: 0 0 33.3333333%;
}
.simple-grid__cell--1\/4 {
flex: 0 0 25%;
}
```
{% demo %}{% include "patterns/simple-grid.njk" %}{% enddemo %}