vertical center text in div css code example

Example 1: css align center

/* This works wonderfully when you know the size of
the thing you are centering. If you don’t know, or are 
thinking it might change and want to be future proof,
try this: */

.centered {
   position: fixed;
   top: 50%;
   left: 50%;
   /* bring your own prefixes */
   transform: translate(-50%, -50%);
}

/* The translate value for transform is based off the size
of the element, so that will center nicely. */

Example 2: css center text in div vertically

<!DOCTYPE html>
<html>
   <head>
      ...
      <style type="text/css">
         div{
         width: 200px;
         height: 200px;
         border: solid green;
         display: table-cell;
         vertical-align: middle;
         }
      </style>
   </head>
   <body>
      <div>Vertikal ausgerichteter Text</div>
   </body>
</html>

Example 3: how to make the text vertically centered in css

/*attention, i used this code because i had to center a div with text in another div without text*/
div{
  position: relative;
  top: 25%;
  bottom: 25%;
}

Example 4: vertical align center text inside div

.center {
  height: 309px;
  line-height: 309px; /* same as height! */
}

Example 5: how to center div

<!DOCTYPE html>
<html>
<head>
<style>
.center {
  margin: auto;
  width: 80%;
  border: 3px solid #73AD21;
  padding: 10px; # deals with margins within the element itself
  margin: 20px; # deals with area around outside of element
}
</style>
</head>
<body>

<h2>Center Align Elements</h2>
<p>To horizontally center a block element (like div), use margin: auto;</p>

<div class="center">
  <p><b>Note: </b>Using margin:auto will not work in IE8, unless a !DOCTYPE is declared.</p>
</div>

</body>
</html>