Skip to content

Instantly share code, notes, and snippets.

@dleitee
Created April 4, 2016 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dleitee/2560b0a851eac191f65bb1ac5c0430a2 to your computer and use it in GitHub Desktop.
Save dleitee/2560b0a851eac191f65bb1ac5c0430a2 to your computer and use it in GitHub Desktop.
Duas maneiras de centralizar um elemento com css.

position

Por ser compatível com browsers menos modernos, talvez essa seja a solução mais adequada na visão geral:

position: absolute;
top: 0; bottom: 0;
left: 0; right: 0;
margin: auto;

Exige altura fixa (height)

Exemplo no JSBin

translateY

position: relative;
top: 50%;
transform: translateY(-50%); 

Suporte: IE9+

Não exige altura fixa (height)

Exemplo no JSBin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment