Using Flexbox to create sticky Header, centered body and sticky footer - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:Flex Center

Description

Using Flexbox to create sticky Header, centered body and sticky footer

Demo Code

ResultView the demo in separate window

<html lang="en">
 <head> 
  <title>  James</title> 
  <style>
html,<!--from  www .  j av  a 2s . co  m-->
body {
   width:100%;
   height:100%;
   margin:0;
   padding:0;
   background-color:Chartreuse;
   text-align:center;
}

.header {
   position:fixed;
   top:0px;
   height:61px;
   line-height:61px;
   width:100%;
   background-color:yellow;
}

.content {
   overflow:scroll;
   padding:61px 0 61px 0;
   display:-webkit-box;
   display:-ms-flexbox;
   display:flex;
   -webkit-box-orient:vertical;
   -webkit-box-direction:normal;
   -ms-flex-direction:column;
   flex-direction:column;
   -webkit-box-align:center;
   -ms-flex-align:center;
   align-items:center;
   -webkit-box-pack:center;
   -ms-flex-pack:center;
   justify-content:center;
}

.content p {
   width:51%;
}

.footer {
   position:fixed;
   bottom:0px;
   height:61px;
   line-height:61px;
   width:100%;
   background-color:blue;
}

.header,
.footer {
   font-weight:bold;
}
</style> 
 </head> 
 <body translate="no"> 
  <div class="header">
    Header 
  </div> 
  <div class="content"> 
   <h1>I am the content</h1> 
   <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p> 
  </div> 
  <div class="footer">
    Footer 
  </div>  
 </body>
</html>

Related Tutorials