Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to display a horizontal scroll bar

Tags:

html

css

I have a div #items which wraps around a whole bunch of .item. I want to display the items side by side, and if they exceed the width of the page, display a horizontal scroll bar.

<div id="somediv"></div>

<div id="items">
   <div class="item">
     Item content
   </div>
</div>

<div id="someotherdiv"></div>

I tried something like this but it does not work

#items{
   overflow: auto;
   width:100%;
   height:200px;       /* this is the height of each item*/ 
}
.item{
   float:left;      
}

I thought this was the way to do it, but I can't get this to way to work, so I'm open to corrections and other ways also.

like image 909
zmol Avatar asked Feb 01 '11 01:02

zmol


People also ask

Why is my horizontal scroll bar not showing up?

column elements are still stacking vertically, but are just out of sight because of the static height of #container and its overflow-y:hidden . This is why a horizontal scroll bar will only appear when you scale the browser down to the width of a single . column .

How do I make a horizontal scroll menu?

To create a horizontal menu first take a div container and add links to it then add CSS property to customize the menu like background-color , text-decoration , padding , margin etc. To add horizontal scroll use overflow: auto and white-space: nowrap .


2 Answers

You are on the right path, but you will need and extra wrapper to make it work...

<div id="scrollable">
<div id="items">
   <div class="item">
     Item content
   </div>
</div>
</div>

and then your CSS:

    #scrollable {
       overflow: auto;
       width:100%;
       height:200px; 
    }

   #items {
     width: 3000px; /* itemWidth x itemCount */
    }

  .item{
     float:left;      
  }
like image 61
methodofaction Avatar answered Oct 04 '22 18:10

methodofaction


This previous question may help: CSS div element - how to show horizontal scroll bars only?

So instead of your current css, change it to:

#items{
    overflow-x: scroll;
    overflow-y: auto;
    width:100%;
    height:200px
}
.item{
    float:left;
}

Try that and adjust if necessary.

like image 37
parent5446 Avatar answered Oct 04 '22 17:10

parent5446