Skip to content

Instantly share code, notes, and snippets.

@Volker-E
Last active August 29, 2015 14:00
Show Gist options
  • Select an option

  • Save Volker-E/11335333 to your computer and use it in GitHub Desktop.

Select an option

Save Volker-E/11335333 to your computer and use it in GitHub Desktop.
CSS center horizontally + vertically undefined height
// 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