user13673
30
Q:

css center vertically

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

/* With Flexbox */

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


9
.parent-class {
  display: flex;
  align-items: center;
  justify-content: space-around;
}
3

  .center {
  display: flex;
  justify-content: center;
  
  align-items: center;
  height: 200px;
  border: 3px solid 
  green; 
} 
3
/* 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;
}
5
<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>
4

.center
{

  margin: auto;

   
width: 50%;

   
border: 3px solid green;
  padding: 10px;

} 
4
.container{
  display: table;
}

.div-inside-container{
  display: table-cell;
  vertical-align: middle;
}
3
.center {
  margin: 0;
  position: absolute;
  top: 50%;
  left: 50%;
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
}
-1

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

  <style>
.content {
  max-width: 500px;
  
  margin: auto;
}
</style>

  <body>

<div class="content">
  <!-- Page content -->
</div>

</body> 
3

New to Communities?

Join the community