Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.