I have a main container with several sub-containers inside. When the main container's width exceeds its limit, I want to display a horizontal scroll bar.
Instead of using the 'display: inline-block' property because it creates unwanted white spaces between the sub-containers.
Here is my solution:
.main-container{
width:250px;
overflow-x:auto;
height:100px;
white-space: nowrap;
}
.sub-container{
width:250px;
height:100px;
float:left;
border:1px solid red;
box-sizing:border-box;
}
<div class="main-container">
<div class="sub-container">Sub-container 1</div>
<div class="sub-container">Sub-container 2</div>
<div class="sub-container">Sub-container 3</div>
<div class="sub-container">Sub-container 4</div>
</div>