Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two divs scrolling independently

Tags:

html

css

scroll


I need help to make these two <div>'s (#side-nav and #content-wrapper) to scroll independently,

HTML:

<div id="wrapper">
    <div id="top-nav">
        Top nav
    </div>
    <div id="side-nav">
        <ul>
            <li>Thing</li>
            <li>Thing</li>
        </ul>
    </div>
    <div id="content-wrapper">
        <!-- Ton of conent here -->
    </div>
</div>

CSS:

#wrapper {
  width: 100%;
  background-color: #fff;
}

#top-nav {
  position: fixed;
  top: 0;
  height: 60px;
  width: 100%;
  background-color: green;
}

#side-nav {
  position: fixed;
  width: 250px;
  height:100vh;
  overflow-y: scroll;
  background-color: red;
}

#content-wrapper {
  margin: 60px 0 0 250px;
  padding: 0 30px;
  overflow-y: scroll;
  background-color: blue;
}

now if I scroll the #side-nav to the end or top, #content-wrapper will scroll too. #side-nav has to stay full-page height and fixed even if there is not that many <li>'s.

I've quickly made pen here:

http://codepen.io/blizqery/pen/QbZzRN

Thanks!

like image 635
Ladislav Tomsa Avatar asked Jul 27 '15 08:07

Ladislav Tomsa


1 Answers

Check this: http://codepen.io/anon/pen/xGyMjM

You need to set height to content-wrapper, and also set the left, right & top.

#side-nav {
  position: fixed;
  width: 250px;
  height:100vh;
  left: 0;
  right: 0;
  overflow-y: scroll;
  background-color: red;
  top: 60px;
}

#content-wrapper {
  margin: 60px 0 0 250px;
  padding: 0 30px;
  overflow-y: scroll;
  position: fixed;
  left: 0;
  top: 0;
  height:100vh;
  background-color: blue;
}
like image 162
Surya Chandra Rao Gandreddi Avatar answered Oct 15 '22 16:10

Surya Chandra Rao Gandreddi