1
0
mirror of https://github.com/phuoc-ng/csslayout.git synced 2025-08-13 17:44:19 +02:00

feat: Sticky header

This commit is contained in:
Phuoc Nguyen
2022-09-21 14:19:27 +07:00
parent fca0ba27f2
commit 8191785762
7 changed files with 56 additions and 141 deletions

View File

@@ -0,0 +1,6 @@
<div class="sticky-header">
<div class="sticky-header__header">
{% rectangle %}
</div>
{% lines "hor", 10 %}
</div>

View File

@@ -117,6 +117,7 @@ eleventyExcludeFromCollections: true
{% pattern "Simple grid" %}{% include "patterns/simple-grid.njk" %}{% endpattern %}
{% pattern "Split screen" %}{% include "patterns/split-screen.njk" %}{% endpattern %}
{% pattern "Sticky footer" %}{% include "patterns/sticky-footer.njk" %}{% endpattern %}
{% pattern "Sticky header" %}{% include "patterns/sticky-header.njk" %}{% endpattern %}
</div>
</div>

31
contents/sticky-header.md Normal file
View File

@@ -0,0 +1,31 @@
---
layout: layouts/post.njk
title: Sticky header
description: Create a sticky header with CSS
keywords: css layout, css position sticky, css sticky header
---
## HTML
```html
<div>
<header class="sticky-header__header">
...
</header>
<main>
...
</main>
</div>
```
## CSS
```css
.sticky-header__header {
/* Stick to the top */
position: sticky;
top: 0;
}
```
{% demo %}{% include "patterns/sticky-header.njk" %}{% enddemo %}

View File

@@ -1,80 +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 Block from '../../placeholders/Block';
import BrowserFrame from '../../placeholders/BrowserFrame';
import Rectangle from '../../placeholders/Rectangle';
const Details: React.FC<{}> = () => {
return (
<PatternLayout pattern={Pattern.StickyHeader}>
<Head>
<meta name="description" content="Create a sticky header with CSS" />
<meta name="og:description" content="Create a sticky header with CSS" />
<meta name="twitter:description" content="Create a sticky header with CSS" />
<meta name="keywords" content="css layout, css position sticky, css sticky header" />
</Head>
<div style={{ lineHeight: 1.5, marginBottom: '16px' }}>
Try to scroll the main content to see the header sticks to the top of page.
</div>
<BrowserFrame
html={`
<div>
<header class="header">
...
</header>
<main>
...
</main>
</div>
`}
css={`
.header {
/* Stick to the top */
position: sticky;
top: 0;
}
`}
>
<div>
<div
style={{
backgroundColor: '#FFF',
borderBottom: '1px solid #d1d5db',
padding: '16px',
position: 'sticky',
top: 0,
}}
>
<div style={{ width: '50%' }}>
<Rectangle />
</div>
</div>
<div style={{ padding: '16px' }}>
<div style={{ marginBottom: '32px' }}>
<Block numberOfBlocks={20} />
</div>
<div style={{ marginBottom: '32px' }}>
<Block numberOfBlocks={40} />
</div>
<div>
<Block numberOfBlocks={30} />
</div>
</div>
</div>
</BrowserFrame>
<Spacer size="extraLarge" />
<RelatedPatterns
patterns={[Pattern.StickySections, Pattern.StickyTableColumn, Pattern.StickyTableHeaders]}
/>
</PatternLayout>
);
};
export default Details;

View File

@@ -1,61 +0,0 @@
import * as React from 'react';
import Frame from '../../placeholders/Frame';
import Line from '../../placeholders/Line';
const Cover: React.FC<{}> = () => {
return (
<Frame>
<div
style={{
display: 'flex',
flexDirection: 'column',
height: '100%',
}}
>
<div style={{ flexShrink: 0 }}>
<div
style={{
alignItems: 'center',
display: 'flex',
padding: '8px',
width: '100%',
}}
>
<div style={{ width: '16px' }}>
<Line />
</div>
<div style={{ marginLeft: 'auto', width: '16px' }}>
<Line />
</div>
<div style={{ marginLeft: '4px', width: '16px' }}>
<Line />
</div>
</div>
<Line />
</div>
<div
style={{
borderRight: '1px solid #d1d5db',
borderWidth: '4px',
flexGrow: 1,
}}
>
<div style={{ padding: '8px' }}>
<div style={{ marginBottom: '8px', width: '64px' }}>
<Line />
</div>
<div style={{ marginBottom: '8px', width: '64px' }}>
<Line />
</div>
<div style={{ width: '32px' }}>
<Line />
</div>
</div>
</div>
</div>
</Frame>
);
};
export default Cover;

View File

@@ -81,6 +81,7 @@
@import './patterns/status-light';
@import './patterns/stepper-input';
@import './patterns/sticky-footer';
@import './patterns/sticky-header';
@import './patterns/sticky-table-column';
@import './patterns/sticky-table-headers';
@import './patterns/switch';

View File

@@ -0,0 +1,17 @@
.sticky-header {
/* Demo */
border: 1px solid #d1d5db;
border-radius: 0.25rem;
height: 100%;
width: 100%;
}
.sticky-header__header {
/* Stick to the top */
position: sticky;
top: 0;
/* Demo */
padding: 0.25rem;
border-bottom: 1px solid #d1d5db;
}