Skip to content

Instantly share code, notes, and snippets.

@blackfalcon
Created August 10, 2013 20:05
Show Gist options
  • Select an option

  • Save blackfalcon/6201936 to your computer and use it in GitHub Desktop.

Select an option

Save blackfalcon/6201936 to your computer and use it in GitHub Desktop.
Absolute Horizontal And Vertical Centering In CSS
// ----
// Sass (v3.2.10)
// Compass (v0.13.alpha.4)
// ----
// http://coding.smashingmagazine.com/2013/08/09/absolute-horizontal-vertical-centering-css/
=absolute-center($width, $height)
width: $width
height: $height
margin: auto
position: absolute
top: 0
left: 0
bottom: 0
right: 0
div
width: 40%
height: 20%
left: 50%
top: 50%
position: absolute
transform: translate(-50%, -50%)
div {
width: 40%;
height: 20%;
left: 50%;
top: 50%;
position: absolute;
transform: translate(-50%, -50%);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment