Skip to content

Instantly share code, notes, and snippets.

@ifeiwu
Last active November 19, 2018 08:59
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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