1
0
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:
Phuoc Nguyen
2022-09-21 14:00:34 +07:00
parent e6f6a31ca0
commit fca0ba27f2
7 changed files with 79 additions and 177 deletions

View 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>

View File

@@ -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
View 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 %}