Skip to content

Instantly share code, notes, and snippets.

@jhafner
Created August 19, 2013 14:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jhafner/6269514 to your computer and use it in GitHub Desktop.
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…
.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