<div class="wrap">
  <div class="child">
     We’ve all seen margin: 0 auto; for horizontal centering, but margin: auto; has refused to work for vertical centering…
  </div>
</div>
body {
  background: #f06d06;
  padding-top: 40px;
}
.wrap {
  position: relative;
  background: #fff;
  border-radius: 5px;
  width: 300px;
  height: 300px;
  margin: 0 auto;
}
.child {
  position: absolute;
  border: 1px solid #eee;
  border-radius: 5px;
  top: 0; bottom: 0; left: 0; right: 0;
  width: 150px;
  height: 60%;
  /*必须设置高度,可以使用百分比,否则将沾满父元素高度*/
  margin: auto;
  color: #666;
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.