Last active
February 6, 2017 17:45
-
-
Save thebigtine/2456c82cca762b59fd320aa473b52dbe to your computer and use it in GitHub Desktop.
A script that centers a element inside its parent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function centerVertical(child, parent, property) { | |
var parentHeight = parent.height(), | |
childHeight = child.height(); | |
// Position the child with an inline style | |
child.css(property, (parentHeight - childHeight) / 2); | |
} centerVertical($('.js-vertical-align-child'), $('.js-vertical-align-parent'), 'margin-top'); |
Use translateY(…)
instead of translate(0, …)
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just use this: