Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make a single row of divs with horizontal scroll bars

Tags:

html

css

Ok so I thought I had this fixed using white-space:no-wrap it worked in chrome but nothing else.

I have something like this:

<div class="outer">
    <ul>

        <li>
          <div class="inner">
            <a href="#"><img src="eg1.jpg" /></a>
            <br />
            EG1 lorem ipsum
           </div>
        </li>

        <li>
          <div class="inner">
            <a href="#"><img src="eg2.jpg" /></a>
            <br />
            EG2 lorem ipsum
           </div>
        </li>
.
.
.
//etc (multiple li's)

</ul>

</div>

excuse the really poor image but this is the efect im aiming for. enter image description here

I want a single row of 'items' if they exceed the space then horizontal scroll bars should appear.

hope that makes sense, how can i achieve this?

like image 736
raklos Avatar asked Feb 29 '12 12:02

raklos


People also ask

How do I make a horizontal scrollable div?

Set the overflow-y: hidden; and overflow-x: auto; that will automatically hide the vertical scroll bar and present only the horizontal scrollbar. The white-space: nowrap; property is used to wrap text in a single line. Here the scroll div will be horizontally scrollable.

How do you make a div row scrollable?

It can be done by the following approach: Approach: Making all the div element in inline using display: inline-block; property. Adding the scroll bar to all the div element using overflow-x: auto; property.

How do I create a horizontal scrolling container?

To enable horizontal scrolling, we can use the CSS property overflow-x. If we assign the value scroll to the overflow-x property of the container element, the browser will hide horizontally overflowing content and make it accessible via horizontal scrolling.

Does scrollIntoView work horizontally?

((JavascriptExecutor) driver). executeScript("arguments[0]. scrollIntoView(true);", element); This works for vertical scrolling but not for horizontal.


1 Answers

Write like this:

.outer{
    width:400px;
    overflow:auto;
    white-space:nowrap;
}
.outer li{
    display: inline-block;
    *display: inline;/*For IE7*/
    *zoom:1;/*For IE7*/
    vertical-align:top;
    width:40px;
    margin-right:20px;
    background:red;
    white-space:normal;
}

Check this http://jsfiddle.net/ZrpHv/

like image 165
sandeep Avatar answered Oct 15 '22 16:10

sandeep