mirror of
https://github.com/phuoc-ng/csslayout.git
synced 2025-08-13 09:35:59 +02:00
feat: Sticky header
This commit is contained in:
6
contents/_includes/patterns/sticky-header.njk
Normal file
6
contents/_includes/patterns/sticky-header.njk
Normal file
@@ -0,0 +1,6 @@
|
||||
<div class="sticky-header">
|
||||
<div class="sticky-header__header">
|
||||
{% rectangle %}
|
||||
</div>
|
||||
{% lines "hor", 10 %}
|
||||
</div>
|
@@ -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
31
contents/sticky-header.md
Normal 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 %}
|
@@ -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;
|
@@ -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;
|
@@ -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';
|
||||
|
17
styles/patterns/_sticky-header.scss
Normal file
17
styles/patterns/_sticky-header.scss
Normal 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;
|
||||
}
|
Reference in New Issue
Block a user