css vertical center

CSS
/* No Flexbox */
.parent {
  position: relative;
}
.child {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
}

/* With Flexbox */

.parent {
  display: flex;
  flex-direction: column;
  justify-content: center;
}


<style>
.container {
  height: 200px;
  position: relative;
  border: 3px solid green;
}

.center {
  margin: 0;
  position: absolute;
  top: 50%;
  left: 50%;
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
}
</style>

<div class="container">
  <div class="center">
    <p>I am vertically and horizontally centered.</p>
  </div>
</div>  <style>
.container { 
  height: 200px;
  position: 
  relative;
  border: 3px solid green; 
}

.center {
  margin: 0;
  
  position: absolute;
  top: 50%;
  left: 50%;
  -ms-transform: 
  translate(-50%, -50%);
  transform: translate(-50%, -50%);
}
</style>

<div 
  class="container">
  <div class="center">
    
  <p>I am vertically and horizontally centered.</p>
  </div>
</div> /* Answer to: "css vertical align middle" */

/*
  Go to: https://www.w3schools.com/css/css_align.asp
  Here you can learn many ways to align horizontal and vertically!
  My favourite method is below:
*/

.center {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 200px;
  border: 3px solid green;
}.parent-class {
  display: flex;
  align-items: center;
  justify-content: space-around;
}.container{
  display: table;
}

.div-inside-container{
  display: table-cell;
  vertical-align: middle;
}
Source

Also in CSS: