Skip to content

Instantly share code, notes, and snippets.

@exarcheia-web
Created December 17, 2013 19:47
Show Gist options
  • Save exarcheia-web/8011382 to your computer and use it in GitHub Desktop.
Save exarcheia-web/8011382 to your computer and use it in GitHub Desktop.
Centering elements with position: absolute
/* Centering elements with position: absolute */
.method1 {
width: 340px;
height: 160px;
background: gainsboro;
text-align: center;
position: absolute;
top: 50%;
left: 50%;
margin-left: -170px;
margin-top: -80px;
line-height: 120px;
}
.method2 {
width: 320px;
height: 140px;
background: hotpink;
text-align: center;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
margin: auto;
}
<div class="method1">Method1</div>
<div class="method2">Method2</div>
// alert('Hello world!');
{"view":"split","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