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
.block
+absolute-center(500px, 500px)
.block {
width: 500px;
height: 500px;
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