Skip to content

Instantly share code, notes, and snippets.

@iamstarkov
Created May 15, 2012 07:03
Show Gist options
  • Save iamstarkov/2699675 to your computer and use it in GitHub Desktop.
Save iamstarkov/2699675 to your computer and use it in GitHub Desktop.
Untitled
/**
* CSS-only: How can I center fixed width div between two divs that fill the remaining space?
*/
#main {
height: 40px;
width: auto;
border: 1px solid #cfcfcf;
position: relative;
}
.half {
width: 50%;
height: 100%;
position: absolute;
top: 0;
}
.half.left { left: 0; }
.half.right { right: 0; }
.half > div {
height: 100%;
padding:0 8px;
}
.half.left > div { padding-left: 7px; }
.half.right > div { padding-right: 7px; }
.col {
height: 100%;
margin-top: 3px;
}
#a,
#c {
background-color: green;
}
#b {
background-color: red;
margin-left: auto;
margin-right: auto;
width: 14px;
}
<div id="main">
<div class="half left">
<div>
<div id="a" class="col"> </div>
</div>
</div>
<div class="half right">
<div>
<div id="c" class="col"> </div>
</div>
</div>
<div id="b" class="col"> </div>
</div>
{"view":"separate","fontsize":"100","seethrough":"1","prefixfree":"1","page":"all"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment