Foreword
As Quentin mentioned,
Basic maths. *
has higher precedence than -
.
So you need to use width: calc( 100% * (2/3 - 1/3));
code.
Problem
div
s are ill-positioned.
Solution
Inner div
s should have position: absolute;
and outer div
should have position: absolute
.
Inner div
s will be placed relative to outer div
and thus, blanks will not occur.
window.onload = function() {
var box = document.querySelector('#container .box');
box.innerText = getComputedStyle( box ).width
}
#container {
width: 300px;
height: 100px;
background: #444;
position:relative;
}
.box {
width: 66.666%;
width: calc( 100% * 2/3);
height: 80px;
background: #09F;
position:absolute;
}
.twee {
background: red;
height: 80px;
width: calc( 100% * (2/3 - 1/3));
position:absolute;
}
<div id="container">
<div class="box"></div>
<div class="twee"></div>
</div>
Appendix
If you wish the red div
to pass to the right, then add right:0
to it.
window.onload = function() {
var box = document.querySelector('#container .box');
box.innerText = getComputedStyle( box ).width
}
#container {
width: 300px;
height: 100px;
background: #444;
position:relative;
}
.box {
width: 66.666%;
width: calc( 100% * 2/3);
height: 80px;
background: #09F;
position:absolute;
}
.twee {
background: red;
height: 80px;
width: calc( 100% * (2/3 - 1/3));
position:absolute;
right:0
}
<div id="container">
<div class="box"></div>
<div class="twee"></div>
</div>