Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have only a vertical scroll bar on a div

I have a table which is in a div. The length of the table can vary and I use the div to enforce a height.

<div id='CamListDiv'>
<table>
    <thead>
        <th><input type='checkbox' id='selectAll'/></th>
        <th>Local Camera List</th>
    </thead>
    <tbody>
        <tr><td>//camera 1 data //</td></tr>
        <tr><td>...</td></tr>
        <tr><td>//camera x data //</td></tr>
    </tbody>
</table>
</div>

CSS
#CamListDiv {
    height: 340px;
    float: left;
    overflow: auto;
    overflow-y: hidden;
}

My problem is when the vertical scrollbar is needed, the space it occupies causes a horizontal scrollbar to appear. I don't need the horizontal scrollbar and I tried to use the overflow-y: hidden; css property to hide it but this causes both scrollbars to be hidden.

Does anyone know why overflow-y:hidden; isn't working as expected or how to stop the horizontal scrollbar from being visible?

like image 775
DarylF Avatar asked Mar 30 '12 09:03

DarylF


1 Answers

You are hiding the vertical scrollbar, and not the horizontal one.

Change overflow-y: hidden; to overflow-x: hidden;


Heres a quick demo

I've added content surpassing the height, and a div with a width greater than 340px inside #CamListDiv. The content is only scrollable vertically.

like image 173
Curtis Avatar answered Oct 11 '22 14:10

Curtis