Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertical Scroll Bars in specific DIV containers only

I'm building a page that has a list on the left, and a container showing a single item's details on the right. Here is a sample image showing the page layout and the parts I want to scroll.

enter image description here

In both the left container and the right container, I need to scroll when the data exceeds the container's viewport height. I only want the red-highlighted containers to scroll--the outer blue container is fixed, and the yellow portion inside the blue container is fixed. Only the red containers' contents should scroll, only when applicable.

I've put up a codepen where I'm playing around with it and can share it with you (the app itself is behind firewall, codepen is the best I can do). What you'll see on the codepen is that I can get the container to scroll when I set it's height (in this case, 380px, which is loosely about how much space is there on screen). If you move the sample codepen's container up, you'll see the scroll area stays fixed (duh), and if you increase the height of the scrollable container beyond 380px, once you go below viewport, scrolling starts to go away--at around 800px or so it completely goes away.

What the heck am I missing here? The blue containers should size themselves to the bottom of the viewport, whether it's 800px high or 1600px high. Then The red container's height would fill that available height inside the blue container, and scroll if necessary.

I'm really stumped on what I'm missing here.

Edit: jQuery and javascript sizing are not options. This is achievable by CSS only, I'm just missing some property somewhere and am stumped.

Edit 2: I tried the suggested html (html: height:100%, etc). It works in codepen, but when I attempt it on my full version of the site, it doesn't work. In the screenshot here, you can see the blue high-lighted area is the scroll container in question, and the white bar on the right is the scrollbar (custom-styled background) but no actual scroll--just the bar background. enter image description here

like image 478
Mike Earley Avatar asked Jan 07 '14 16:01

Mike Earley


People also ask

How to show only horizontal and vertical scroll bar in Div?

CSS to show only horizontal and vertical scroll bar in div Sometimes we need to add scroll bar to a div or span whenever text in the div or span get overflow. scroll bar is supported in all browsers like IE 5+, FF 3.5+, and Safari, Opera etc. To show scroll bar, we need to specify overflow property of css to "visible" or "auto".

How to create a vertical scrollable bar in WordPress?

For vertical scrollable bar use the x and y axis. Set the overflow-x:hidden; and overflow-y:auto; that will automatically hide the horizontal scroll bar and present only vertical scrollbar. Here the scroll div will be vertically scrollable. Attention reader!

How do I make a scrollable Div in HTML?

For a scrollable bar, use the x and y-axis. Set the overflow-x: hidden; and overflow-y: auto; to automatically hide the horizontal scrollbar and show a vertical scrollbar. Let’s see an example, where the <div> is vertically scrollable.

Can I put a scrollbar in a fixed height container?

I assumed it would work out from the container that it wouldn't fit, and apply scrollbars on that basis. If you give Content a fixed height, you shouldn't give FixedHeightContainer a fixed height, because you can't know how high your title will be, so Content may be pushed out.


1 Answers

I have implemented a basic version which should help you out.

You can find the code over at https://codepen.io/hunzaboy/pen/aWmMeJ .

Here is the CSS

body,
html {
  overflow: hidden;
}

.wrapper {
  display: flex;
  height: 100vh;
}

.sidebar {
  width: 20%;
  background: blue;
  color: white;
  overflow-y: scroll;
}

.content {
  background: yellow;
  color: brown;
  overflow-y: scroll;
}
like image 188
Aslam Avatar answered Oct 06 '22 23:10

Aslam