Skip to content

Instantly share code, notes, and snippets.

@mcranston18
Created October 30, 2013 15:20
Show Gist options
  • Save mcranston18/7234442 to your computer and use it in GitHub Desktop.
Save mcranston18/7234442 to your computer and use it in GitHub Desktop.
Directive to vertically align in CSS
app.directive('verticalAlign', function () {
return {
restrict: 'A',
link: function (scope, elm, attrs) {
var childHeight = elm[0].clientHeight;
var parentHeight = elm[0].parentElement.clientHeight;
var offset = (parentHeight - childHeight) / 2;
elm[0].style.paddingTop = offset + 'px';
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment