mirror of
https://github.com/phuoc-ng/csslayout.git
synced 2025-08-29 16:49:58 +02:00
feat: Sticky footer
This commit is contained in:
5
contents/_includes/patterns/sticky-footer.njk
Normal file
5
contents/_includes/patterns/sticky-footer.njk
Normal file
@@ -0,0 +1,5 @@
|
||||
<div class="sticky-footer">
|
||||
<div class="sticky-footer__header">{% rectangle %}</div>
|
||||
<div class="sticky-footer__main">{% lines "hor", 5 %}</div>
|
||||
<div class="sticky-footer__footer">{% rectangle %}</div>
|
||||
</div>
|
@@ -116,6 +116,7 @@ eleventyExcludeFromCollections: true
|
||||
{% pattern "Sidebar" %}{% include "patterns/sidebar.njk" %}{% endpattern %}
|
||||
{% 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 %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
45
contents/sticky-footer.md
Normal file
45
contents/sticky-footer.md
Normal file
@@ -0,0 +1,45 @@
|
||||
---
|
||||
layout: layouts/post.njk
|
||||
title: Sticky footer
|
||||
description: Create a sticky footer with CSS flexbox
|
||||
keywords: css flexbox, css layout, css sticky, css sticky footer
|
||||
---
|
||||
|
||||
## HTML
|
||||
|
||||
```html
|
||||
<div class="sticky-footer">
|
||||
<header class="sticky-footer__header">
|
||||
...
|
||||
</header>
|
||||
<main class="sticky-footer__main">
|
||||
...
|
||||
</main>
|
||||
<footer class="sticky-footer__footer">
|
||||
...
|
||||
</footer>
|
||||
</div>
|
||||
```
|
||||
|
||||
## CSS
|
||||
|
||||
```css
|
||||
.sticky-footer {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.sticky-footer__header,
|
||||
.sticky-footer__footer {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.sticky-footer__main {
|
||||
flex-grow: 1;
|
||||
}
|
||||
```
|
||||
|
||||
The footer always sticks to the bottom if the main content is short.
|
||||
|
||||
{% demo %}{% include "patterns/sticky-footer.njk" %}{% enddemo %}
|
Reference in New Issue
Block a user