Created
August 19, 2013 14:06
-
-
Save jhafner/6269514 to your computer and use it in GitHub Desktop.
Absolute centering of elements with CSS. Advantages:
Cross-browser (including IE8-10)
No special markup, minimal styles
Responsive with percentages and min-/max-
Use one class to center any content
Centered regardless of padding (without box-sizing!)
Blocks can easily be resized
Works great on images Caveats:
Height must be declared
Recommend se…
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
.Center-Container { | |
position: relative; | |
} | |
.Absolute-Center { | |
width: 50%; | |
height: 50%; | |
overflow: auto; | |
margin: auto; | |
position: absolute; | |
top: 0; left: 0; bottom: 0; right: 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment