Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS: Make only side menu scrollable

EXAMPLE is here http://jsfiddle.net/zsSrZ/

The page itself is unscrollable and so is the content in #container but I can't figure out how to make the side navigation scrollable. In the example I have overfilled #menu with li's so it spills off the page but You don't see it because overflow is set to off on the body.

HTML

<div id="menu">
  <ul>
    <li></li>
        .
        . 
        .
        .
        .
    <li></li>
  </ul>
</div>

<div id="container"></div>

CSS

#container {
  position:absolute;
  width:100%;
  top:0;
  bottom:0;
  z-index:-1;
  overflow:hidden;
  background:red;
}

#menu {
  width:200px;
  background:white;
  float:left;
  height:100%;
  margin-top:54px
}
like image 921
Christopher Reid Avatar asked Nov 23 '25 19:11

Christopher Reid


2 Answers

I'm just giving you an example of how I did one of my tables using the overflow scroll. you should set a height then say if you want the scroll on the y axis or the x axis e.g. overflow-y.

The CSS for my table:

#exampletable {
    margin-left: auto;
    margin-right: auto;
    overflow-y: auto;
    height: 150px;
    width: 680px;
}
like image 125
HaydnJW Avatar answered Nov 28 '25 05:11

HaydnJW


I found a good way to do this with a variable height. Giving the menu position:absolute; instead of float you can anchor it with either top:0; or bottom:0;. Setting height:100% restricts the menu to window height and overflow:scroll lets you see what gets cut off. Everything else can be set to overflow:hidden;

http://jsfiddle.net/zsSrZ/4/

#container {
    position: absolute;
    width: 100%;
    top: 0;
    bottom: 0;
    z-index: -1;
    overflow: hidden;
    background: red;
}

#menu {
    width: 200px;
    background: blue;
    position: absolute;
    overflow: scroll;
    top: 0px;
    height: 100%;
    padding-top: 10px;
}
like image 38
Christopher Reid Avatar answered Nov 28 '25 03:11

Christopher Reid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!