Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
CSS3元素垂直居中

HTML

<div class="vertical-container">
  <div class="vertical-center">Centered</div>
</div>

CSS

.vertical-container {
  width: 200px;
  height: 200px;
  position: relative;
  margin: 0 auto;
  background: #fff;
}

.vertical-center {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment