Skip to content

Instantly share code, notes, and snippets.

@csssecrets
Created November 13, 2014 10:54
Show Gist options
  • Save csssecrets/bf12b39d8f5da2b6e5b6 to your computer and use it in GitHub Desktop.
Save csssecrets/bf12b39d8f5da2b6e5b6 to your computer and use it in GitHub Desktop.
Vertical centering - Viewport unit method
/**
* Vertical centering - Viewport unit method
*/
main {
width: 18em;
padding: 1em 1.5em;
margin: 50vh auto 0;
transform: translateY(-50%);
box-sizing: border-box;
background: #655;
color: white;
text-align: center;
}
h1 {
margin: 0 0 .2em;
font-size: 150%;
}
p {
margin: 0;
}
body {
background: #fb3;
font: 100%/1.5 sans-serif;
}
<main>
<h1>Am I centered yet?</h1>
<p>Center me, please!</p>
</main>
// alert('Hello world!');
{"view":"split-vertical","fontsize":"100","seethrough":"","prefixfree":"1","page":"css"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment