Skip to content

Instantly share code, notes, and snippets.

@kiaratto
Last active November 28, 2016 17:31
Show Gist options
  • Save kiaratto/7141ea7155e2df9528080fc6bffcef75 to your computer and use it in GitHub Desktop.
Save kiaratto/7141ea7155e2df9528080fc6bffcef75 to your computer and use it in GitHub Desktop.
Centraliza um elemento html dentro de outro elemento verticalmente. Funciona após o html montado já que utilizo o offsetHeight. Para centralizar horizontalmente utiliza-se o truque do margin:0 auto; na classe de estilo
function CentralizaVerticalmente(elemento){
elemento.style.marginTop = ((elemento.parentElement.offsetHeight / 2) - (elemento.offsetHeight / 2)) + "px";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment