1

basically I have to achieve the stacic scrolling content section part. The top static border, and the bottom static border have to stay always visible regardless of the size of the browser, and the static scrolling content should adapt to this resizing happening.

enter image description here

I've been playing quite a lot with the overflow-y:hidden container with a overflow-y:scroll in a child container with no success.

This is what I've been trying:

    .vertical-scroll-viewer {
    overflow: auto;
    height: 100%;
    /*height: 100%;
    width: 100%;
    border: 1px solid green;
    overflow: hidden;*/
}

    .vertical-scroll-viewer-content {
    overflow: hidden;
    height: 100%;
    /*
    height: 99%;
    border: 1px solid blue;
    overflow: auto;
    padding-right: 15px;*/
}

And the HTML:

  <html>
<head>   
    <title>test</title>
</head>
<body>
    <h1> Header1</h1>
    <div class="vertical-scroll-viewer">

        <div class="vertical-scroll-viewer-content ">
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
            <div>  hi  </div>
        </div>
    </div>
    <h1> Header2</h1>
</body>
</html>

Header 2 dissapears below the scrollbar.

Does anyone know how to make this? Thanks!

4
  • 4
    Please, show what you tried. Both markup and css. Commented Jun 3, 2019 at 7:28
  • please add your code that you have tried. Commented Jun 3, 2019 at 7:35
  • I edited the question with the HTML and the CSS Commented Jun 3, 2019 at 7:51
  • While CSS scrollbar style support is a bit scattered it's getting better. Your closest to universal support would be something such as scrollbar-color: #000 #fff; though if you want to create your own don't forget about accessibility. Commented Jun 4, 2019 at 5:03

2 Answers 2

3

This works well.

Notice the reset of the html/body and the use of vh,vw instead of 100%

html, body { height: 100vh; margin: 0; }

.container {
  width: 100vw;
  height: 100vh;
  background: aqua;
  margin: auto;
  padding: 1px;
}

#right {
  margin-left: 15vw;
  height: 100vh;
  background: yellow;
  overflow:scroll;
}

.static {
  height: 50px;
  background: green;
}

#bottom {
  width: 100%;
  position: absolute;
  bottom: 0;
}

#left {
  width: 15vw;
  height: 100vh;
  background: red;
  float: left;
  position: absolute;
}

#middle {
  height: calc(100vh - 100px);
  overflow-y: scroll; /* it will work */
}
<section class="container">
  <div id="left">
    <div id="top" class="static">Top</div>
    <div id="middle">
      <h2>Middle</h2>
      <p style="height: 9001px;">Lorem ipsum</p>
      <p>Lorem ipsum</p>
    </div>
    <div id="bottom" class="static">Bottom</div>
  </div>
  <div id="right" class="scroll">
    <h2>Right</h2>
    <p style="height: 9001px;">Lorem ipsum</p>
    <p>Lorem ipsum</p>
  </div>
</section>

Sign up to request clarification or add additional context in comments.

3 Comments

Yes is more or less what I need, but the Middle section should stay always visible, and the bottom part too. The Middle section + top + bottom should be always visible, regardless the Right section.
Hi, it worked when I copied it in a local html file. the top, bottom part are always shown, but If I scroll in the main part it will scroll everything also. Is there any way to make it static as the menu in StackOverflow? I'll mark it as answered and ask for who to do the static StackOverflow menuin another question. Thanks again.
I think if you add height: 70vh; instead of height: calc(100vh - 100px); and adding height: 15vh; to the two elements Top and Bottom might work
0
<div id="div1" style="width:200px; height: 500px;position:relative;">
    <div id="div2" style="max-height:100%;overflow:auto;border:1px solid red;">
        <div id="div3" style="height:1500px;border:5px solid yellow;">hello</div>
    </div>
</div>

2 Comments

Please provide some explanation.
Thanks but that solution doesn't adapt to the size of the height of the browser: imgur.com/a/bBCbu8I as you can see the Hello scrollbar dissapears overflowing the bottom.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.