Created
November 2, 2016 14:57
-
-
Save Camwyn/a98d7b0a130304c5cc7bc387781be1ca to your computer and use it in GitHub Desktop.
Centering via position and transform
This file contains hidden or 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
| // Position an element horizontally (requires a 'position: relative' parent) | |
| @mixin horizontal-center { | |
| position: absolute; | |
| left: 50%; | |
| transform: translateX(-50%); | |
| } | |
| // Position an element vertically (requires a 'position: relative' parent) | |
| @mixin vertical-center { | |
| position: absolute; | |
| top: 50%; | |
| transform: translateY(-50%); | |
| } | |
| // Position an element both vertically AND horizontally (requires a 'position: relative' parent) | |
| @mixin center { | |
| left: 50%; | |
| position: absolute; | |
| top: 50%; | |
| transform: translateX(-50%) translateY(-50%); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment