Who needs a grid system anymore? Some useful CSS layouts using
flex
and grid
for any project.
To use, copy the CSS from styles.css and drop it into your project. Then use the the HTML markup below.
<div class="stack">
<div>Stack item 1</div>
<div>Stack item 2</div>
...
</div>
stack-zero
, stack-quarter
,
stack-half
, stack-2x
, stack-4x
<div class="stack-2x">
<div>Stack item 1</div>
<div>Stack item 2</div>
...
</div>
<div class="stack-end">
<div>Stack item 1</div>
<div>Stack item 2</div>
<div>Last stack item</div>
</div>
<div class="inline">
<div>Inline item 1</div>
<div>Inline item 2</div>
...
</div>
inline-zero
, inline-quarter
,
inline-half
, inline-2x
<div class="inline-2x">
<div>Inline item 1</div>
<div>Inline item 2</div>
...
</div>
<div class="inline-between">
<div>Inline item 1</div>
<div>Inline item 2</div>
...
</div>
<div class="inline-wrap">
<div>Inline item 1</div>
<div>Inline item 2</div>
...
</div>
<div class="inline align-top">
<div>Inline item 1</div>
<div>Inline item 2</div>
...
</div>
<div class="stack">
<div class="inline inline-wrap">
<div class="stack">
<label>Label</label>
<input />
</div>
<div class="stack">
<label>Label</label>
<input />
</div>
</div>
<div class="stack">
<label>Label</label>
<input />
</div>
</div>
Content with scrollable sidebar.
On mobile, collapse to 1 column with the order: Header → Sidebar → Content
<div class="grid-sidebar">
<header class="header">Header</header>
<section class="content">Content</section>
<aside class="sidebar">Sidebar</div>
</div>
Uses named sections to order content. Right align an image with a specific aspect ratio.
On mobile, collapse to 1 column with the order: Header → Image → Content
<div class="grid-acb">
<header class="a">Header (Section A)</header>
<div class="b">Content (Section B)</div>
<div class="c">Image (Section C)</div>
</div>
A block of N items per row. Reduce items per row at breakpoints. Modify the number of items per row as needed
<ul class="grid-blocks-4">
<li>Item 1</li>
<li>Item 2</li>
...
</ul>
<ul class="grid-blocks-5">
<li>Item 1</li>
<li>Item 2</li>
...
</ul>
Collapse items per row based on their fixed width (in this case 12rem)
<ul class="grid-inline">
<li>Item 1</li>
<li>Item 2</li>
...
</ul>
When you need a column of content like a blog post, with sections that "break out" eg. image or sections with a different background colour.
Content
Content
Content
<div class="breakout">
<p>Content</p>
<div class="feature">Feature content</p>
<p>Content</p>
<div class="full">Full width content</p>
...
</div>