Skip to content

Instantly share code, notes, and snippets.

@shoxty
Created April 6, 2011 16:42
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 shoxty/906006 to your computer and use it in GitHub Desktop.
Save shoxty/906006 to your computer and use it in GitHub Desktop.
Center a widthless element with CSS
<style type="text/css">
.center-wrapper {overflow: hidden; width: 500px;} //SET THE WIDTH OF YOUR CONTAINER
.center-wrapper .center-wrapper-inner {position: relative; float: left; left: 50%;}
.center-wrapper .center-wrapper-inner .centered-item {float: left; position: relative; right: 50%;}
</style>
<div class="center-wrapper">
<div class="center-wrapper-inner">
<div class="centered-item">
CRAP IN HERE WILL BE CENTERED
</div>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment