Vertically centering elements inside its container - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:Parent Container

Description

Vertically centering elements inside its container

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <style id="compiled-css" type="text/css">
.column-wrapper {<!--from ww  w  . j a va  2  s .c o  m-->
   display:flex;
   flex-direction:row;
   width:100%;
   height:100vh;
   border:2px solid Chartreuse;
   align-items:center;
}

.col-1, .col-2 {
   vertical-align:middle;
   width:51%;
}

.col-1 {
   background:yellow;
}

.col-2 {
   background:blue;
}
</style> 
 </head> 
 <body> 
  <div class="column-wrapper"> 
   <div class="col-1"> 
    <p>I am column 1 with background grey and content centered vertically</p> 
   </div> 
   <div class="col-2"> 
    <p>I am column 2 with background green and content centered vertically</p> 
   </div> 
  </div>  
 </body>
</html>

Related Tutorials