I’m trying to create a horizontal scrolling bar which when overflowed will scroll horizontally at the top of the page. I have tried different combinations of this with overflow values but the inline-div elements that I have in the div with the horizontal settings just creates a line break meaning that the horizontal bar is pointless. This is my code:
CSS:
#files_scroll {
width: 100%;
height: 120px;
background-color: #FFFFFF;
overflow-x: scroll;
overflow-y: hidden;
}
.file_icon {
height: 80px;
margin: 7px;
padding-left: 10px;
display: inline-block;
padding: 5px;
float: left;
background-color: #CCCCCC;
opacity: 0.5;
border-radius: 10px;
width: 90px;
}
<div id="main_content">
<div id="files_scroll">
<a class="file_icon">1</a>
<a class="file_icon">2</a>
<a class="file_icon">3</a>
<a class="file_icon">4</a>
<a class="file_icon">5</a>
<a class="file_icon">6</a>
<a class="file_icon">7</a>
</div>
</div>
If you want horizontal scrolling, you need your content to become larger than the container. It is not possible with floating element or inline element : They fall on the “next line” when there is not enough space left.
2 solutions :
Put your content in an extra-large element.
with CSS:
Use non-floating/non-inline element.
It is easier but… it use a single row table. There are probably alternatives, but I can’t see one right now.
I didn’t touch your CSS at all and this works :