To prevent your body container from adding a new line when running out of space, you can create an extra div with a large width to contain other smaller divs.
Here is the HTML code:
<div id="container" class="clearfix">
<div id="wrapper" class="clearfix">
<div id="div1">Div1</div>
<div id="div2">Div2</div>
<div id="div3">Div3</div>
<div id="div4">Div4</div>
</div>
</div>
And here is the CSS code:
#container {
height: 275px;
overflow-x: auto;
overflow-y: hidden;
max-height: 275px;
}
#wrapper div {
float: right;
border: 1px solid black;
width: 200px;
height: 100px;
display: inline-block;
}
.clearfix:after {
content: " "; /* Older browsers do not support empty content */
visibility: hidden;
display: block;
height: 0;
clear: both;
}
To make the design more dynamic, you can calculate the total width taken by inner divs and adjust the additional space on the wrapper div accordingly using JavaScript:
var width = 0;
$('#wrapper > div').each(function() {
width += parseInt($(this).css('width'));
});
wrapperWidth = width + 100;
$('#wrapper').css('width', wrapperWidth);
You can view an updated demo here.