Skip to content

Instantly share code, notes, and snippets.

@stuartgamblen
Created March 1, 2012 15:46
Show Gist options
  • Save stuartgamblen/1950621 to your computer and use it in GitHub Desktop.
Save stuartgamblen/1950621 to your computer and use it in GitHub Desktop.
CSS: Center inner div with no outer width
/* Center inner div with no outer width */
div.wrapper{
float: left;
overflow: hidden;
position: relative;
width: 100%;
background: #F5F5F5;
padding: 10px;
margin: 0 -20px;
}
div.outer{
clear: left;
float: left;
left: 50%;
list-style: none outside none;
margin: 0;
padding: 0;
position: relative;
text-align: center;
}
div.inner{
display: block;
float: left;
margin: 0;
padding: 0;
position: relative;
right: 50%;
color: #FFF;
padding: 5px 20px;
background: #8CC942;
}
<div class="wrapper">
<div class="outer">
<div class="inner">Centering the DIV</div>
</div>
</div>
{"view":"split-vertical","seethrough":"","prefixfree":"1","page":"all"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment