Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I apply a vertical scrollbar to a div with a percentage height?

I've come across numerous question of the similar nature but my situation is a bit different; my outer container is height 100% instead of a fixed height.

I have a bunch of divs inside a container. They overflow and I want to have a scrollbar to allow scrolling.

This is exactly what I want to achieve: http://jsfiddle.net/jcjw2jmo/

Except, the link I posted has a fixed height: 200px;. I want to have a percentage height instead.

I've tried setting a percentage height and max-height with no luck. Here's my progress: http://jsfiddle.net/k52eh0xr/

How do I get both the fiddles to have the same behaviour but with using percentages instead?

Thanks so much

PS. I know this can be done using Javascript/jQuery but I am looking for a CSS-only solution

like image 689
RainSear Avatar asked Oct 12 '15 01:10

RainSear


People also ask

How do I change the height of my scroll bar?

To get the height of the scroll bar the offsetHeight of div is subtracted from the clientHeight of div. OffsetHeight = Height of an element + Scrollbar Height. ClientHeight = Height of an element. Height of scrollbar = offsetHeight – clientHeight.

Can height be a percentage in CSS?

Without content, the height has no value to calculate the percentage of. The width, however, will take the percentage from the DOM, if no parent is specified.

How do you add height percentage in CSS?

CSS height and width Values length - Defines the height/width in px, cm, etc. % - Defines the height/width in percent of the containing block. initial - Sets the height/width to its default value. inherit - The height/width will be inherited from its parent value.

How do I make my vertical overflow scroll?

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.


1 Answers

I think you need set your html and body tag with height:100% so you can use percent like you want

html, body {height:100%}

DEMO

like image 171
Henry Varro Avatar answered Oct 03 '22 05:10

Henry Varro