Skip to content

Instantly share code, notes, and snippets.

@steppefox
Created October 24, 2013 16:42
Show Gist options
  • Save steppefox/7140642 to your computer and use it in GitHub Desktop.
Save steppefox/7140642 to your computer and use it in GitHub Desktop.
Methods for the placing element at the center
<!-- OLD SCHOOL METHOD FROM 2000 -->
<style>
div.center-2 { position: relative; float: left; left: 50%; margin: 0; padding: 0; z-index:2}
div.center-2 div.center-3 { position: relative; float: left; right: 50%;z-index:2 }
div.center-1 {overflow: hidden;}
</style>
<div class="center-1"><div class="center-2"><div class="center-3">
...
</div></div></div>
<!-- Standart method, when you know width element -->
<style>
#target{
margin: 0 auto;
}
</style>
<!-- Standart method, for absolute element, when you know width of element -->
<style>
#target{
position:absolute;
width:300px;
left:50%;
margin-left:-150px;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment