Centering with pseudo element

suggest change

HTML:

<div class="wrapper">
  <div class="content"></div>
</div>

CSS:

.wrapper{
   min-height: 600px;
}

.wrapper:before{
  content: "";
  display: inline-block;
  height: 100%;
  vertical-align: middle;
}

.content {
  display: inline-block;
  height: 80px;
  vertical-align: middle;
}

This method is best used when a variable-height .content is centered inside .wrapper, and .wrapper should grow once .content exceeds the wrapper’s min-height. Percentage heights need a definite containing-block height; with only min-height, some browsers treat the pseudo-element’s height: 100% as auto.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents