Skip to content

Instantly share code, notes, and snippets.

@DannyJoris
Created June 16, 2014 17:52
Show Gist options
  • Save DannyJoris/07f4a67eda880abb339d to your computer and use it in GitHub Desktop.
Save DannyJoris/07f4a67eda880abb339d to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
<div class="parent">
<div class="children child1">
I'm vertically centered!
<br>- Fixed height in pixels (100px)
</div>
</div>
<div class="parent">
<div class="children child2">
I'm vertically centered!
<br>- auto height
</div>
</div>
<div class="parent">
<div class="children child3">
I'm vertically centered!
<br>- Fixed height larger than parent (300px)
</div>
</div>
<div class="parent">
<div class="children child4">
I'm vertically centered!
<br>- Height in percentage (50%)
</div>
</div>
// ----
// Sass (v3.3.8)
// Compass (v1.0.0.alpha.19)
// ----
// From: http://davidwalsh.name/css-vertical-center
@import "compass";
.parent {
width: 250px;
height: 250px;
margin: 20px;
border: 1px solid hotpink;
display: inline-block;
}
.children{
background: #ffdb4c;
position: relative;
top: 50%;
@include translateY(-50%);
}
.child1 {
height: 100px;
}
.child2 {
height: auto;
}
.child3 {
height: 300px;
}
.child4 {
height: 50%;
}
.parent {
width: 250px;
height: 250px;
margin: 20px;
border: 1px solid hotpink;
display: inline-block;
}
.children {
background: #ffdb4c;
position: relative;
top: 50%;
-moz-transform: translateY(-50%);
-ms-transform: translateY(-50%);
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
}
.child1 {
height: 100px;
}
.child2 {
height: auto;
}
.child3 {
height: 300px;
}
.child4 {
height: 50%;
}
<div class="parent">
<div class="children child1">
I'm vertically centered!
<br>- Fixed height in pixels (100px)
</div>
</div>
<div class="parent">
<div class="children child2">
I'm vertically centered!
<br>- auto height
</div>
</div>
<div class="parent">
<div class="children child3">
I'm vertically centered!
<br>- Fixed height larger than parent (300px)
</div>
</div>
<div class="parent">
<div class="children child4">
I'm vertically centered!
<br>- Height in percentage (50%)
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment