Skip to content

Instantly share code, notes, and snippets.

@csandman
Created June 6, 2019 18:26
Show Gist options
  • Save csandman/adbcfdb70b34f85fa91c14af44dd6797 to your computer and use it in GitHub Desktop.
Save csandman/adbcfdb70b34f85fa91c14af44dd6797 to your computer and use it in GitHub Desktop.
Different ways to center an element with CSS
.container {
position: relative;
}
.object: {
position: absolute;
top: 50%; // moves the element 50% from the top of the container
left: 50%; // moves the element 50% from the left of the container
transform: translate(-50%, -50%); // move the element back up and to the left half of its total size
}
.container-flex {
display: flex;
justify-content: center;
align-items: center;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment