Last active
August 29, 2015 14:00
-
-
Save Volker-E/11335333 to your computer and use it in GitHub Desktop.
CSS center horizontally + vertically undefined height
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
| // Translate mixin | |
| // ------------------------------ | |
| .translate(@x; @y) { | |
| -webkit-transform: translate(@x, @y); | |
| -ms-transform: translate(@x, @y); | |
| -o-transform: translate(@x, @y); | |
| transform: translate(@x, @y); | |
| } | |
| // Center-align mixin | |
| // ------------------------------ | |
| // Center full | |
| .center-full() { | |
| position: absolute; | |
| top: 50%; | |
| left: 50%; | |
| .translate(-50%, -50%); | |
| } | |
| // Center top only | |
| .center-top() { | |
| position: absolute; | |
| top: 50%; | |
| .translate(0, -50%); | |
| } | |
| // Block element | |
| // ------------------------------ | |
| .box { | |
| .center-full(); | |
| color: #222; | |
| height: 50%; | |
| width: 50%; | |
| p { | |
| .center-top(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment