You haven’t given your inline block explicit width. You would experience the same problem even if you used floats, btw.
Without some sort of width, the element will expand to contain it’s contents, so if there is more than one window width of content then the width of your element will be 100%, thus bumping down it’s adjacent elements.
If teh gray square is purely decorative, you could clean up your code and achieve the effect you want like this:
.w:before{
content:'';
width:80px;
height:80px;
background-color:#555;
float:right;
}
.w {width:30%; overflow: hidden}
<div class='w'>
This would be your content. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
if the square represents actual content … then you will have to put that element first in the source order.
if that i snot semantically possible, , the best one can do is ‘make’ space. this mean a column of empty space where the box will reside. of course because you cant mix measurements it will end up beign something like this:
.box{
width:20%;
height:55px;
background-color:#555;
display: inline-block;
margin-left: -.2em /* quick whitespace bug correction*/
}
.w {width:30%; outline:1px solid}
.w .c { display: inline-block;max-width: 80%; }
.c, .box, .w{vertical-align: top;}
<div class='w'>
<div class='c'>This would be your content. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
<div class="box"></div>
</div>
again floats may be a better solution, as they allow you to use margins…
.box{
width:50px;
height:50px;
background-color:#555;
margin-left: -50px;
}
.w {width:30%; outline:1px solid; overflow: hidden}
.w .c { display: inline-block;max-width: 100%; padding-right: 50px; }
.c, .box {float:left}
I hope that helps.