Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make a div scroll horizontally

Tags:

html

css

I want to create a layout in which I will like to align contents in a horizontal direction but let each row scroll-able in horizontal direction only. Here is my JSFiddle Sample.

.x-scroller{
    overflow-x: scroll; 
    overflow-y:hidden; 
    height:100px; 
    width: 300px
}

The .x-scroller DIV will be dynamically generated in a loop with her contents, each of the x-scroller DIV will equally have some contents which I will like to be able to scroll in horizontal direction only as can be seen in the picture below:

The .x-scroller DIV will dynamically generated in a loop with her contents each of the x-scroller DIV will equally have some contents which I will like to be able to scroll in horizontal direction only

like image 298
Paullo Avatar asked Aug 14 '14 16:08

Paullo


People also ask

How do I make my scroll horizontal?

Horizontal scrolling can be achieved by clicking and dragging a horizontal scroll bar, swiping sideways on a desktop trackpad or trackpad mouse, pressing left and right arrow keys, or swiping sideways with one's finger on a touchscreen.

How do you use the scroll wheel horizontally?

Scroll horizontally using a keyboard and mousePress and hold SHIFT. Scroll up or down using your mouse wheel (or another vertical scrolling function of your mouse).

How do you make a div scrollable?

For vertical scrollable bar use the x and y axis. Set the overflow-x:hidden; and overflow-y:auto; that will automatically hide the horizontal scroll bar and present only vertical scrollbar. Here the scroll div will be vertically scrollable.


1 Answers

Is this what you're looking for?

.outer {
    width: 500px;
    height: 100px;
    white-space: nowrap;
    position: relative;
    overflow-x: scroll;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
}

.outer div {
    width: 24.5%;
    background-color: #eee;
    float: none;
    height: 90%;
    margin: 0 0.25%;
    display: inline-block;
    zoom: 1;
}
<div class="outer">
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
</div>
like image 127
John_C Avatar answered Sep 18 '22 19:09

John_C