Created
June 6, 2019 18:26
-
-
Save csandman/adbcfdb70b34f85fa91c14af44dd6797 to your computer and use it in GitHub Desktop.
Different ways to center an element with CSS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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