A Pen by Chris Coyier on CodePen.
Created
January 26, 2018 22:32
-
-
Save ozrabal/c65449368534982792a7e94ec9fe7cb5 to your computer and use it in GitHub Desktop.
Sticky Footer with Flexbox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="content"> | |
<h1>Sticky Footer with Flexbox</h1> | |
<p><button id="add">Add Content</button></p> | |
</div> | |
<footer class="footer"> | |
Footer | |
</footer> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Not required! | |
// This is just to demo functionality. | |
$("#add").on("click", function() { | |
$("<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>").appendTo(".content"); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
html { | |
height: 100%; | |
} | |
body { | |
display: flex; | |
flex-direction: column; | |
height: 100vh; /* Avoid the IE 10-11 `min-height` bug. */ | |
} | |
.content { | |
flex: 1 0 auto; /* Prevent Chrome, Opera, and Safari from letting these items shrink to smaller than their content's default minimum size. */ | |
padding: 20px; | |
} | |
.footer { | |
flex-shrink: 0; /* Prevent Chrome, Opera, and Safari from letting these items shrink to smaller than their content's default minimum size. */ | |
padding: 20px; | |
} | |
* { | |
box-sizing: border-box; | |
} | |
body { | |
margin: 0; | |
font: 16px Sans-Serif; | |
} | |
h1 { | |
margin: 0 0 20px 0; | |
} | |
p { | |
margin: 0 0 20px 0; | |
} | |
footer { | |
background: #42A5F5; | |
color: white; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment