With absolute, it scrolls but doesn't get 100% in height:
.class {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
height: 100%;
width: 100%;
z-index: 1000000;
background: rgba(0, 0, 0, 0.9);
}
With fixed, it gets 100% in height but doesn't scroll
.class {
position: fixed;
left: 0;
top: 0;
height: 100%;
width: 100%;
z-index: 1000000;
background: rgba(0, 0, 0, 0.9);
}
I would like to avoid adding a fixed heigth to the child element and make it 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.
Usually, a scroll box is obtained with the usage of the <div> tag, and the customization for the bar is done using CSS properties. While creating a scroll box, we use a CSS property known as 'overflow' and set it to 'scroll' to let the browser know that it is to add the horizontal and vertical scroll bars.
It can be easily done by using the overflow property. The overflow property has different values. E.g., overflow: auto; and an axis hiding procedure like overflow-x: hidden; and overflow-y: auto; will make a bar scrollable vertically and horizontally, and the "auto" value will add only a vertically scrollable bar.
So first of all, if you want to have 100% height and width, you will have to define WHAT that is. So you have to tell the html/body that the size they have, is 100% width/height.
Now you don't want to let the page scroll down, if the text goes out of the div, because you will see white space if you do. So set overflow-y to scroll, so it will scroll inside the div, and not in the document itself.
html,body{
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.fullwidth{
width:100%;
height: 100%;
background-color: red;
overflow-y: scroll;
}
Here is a working fiddle:
WORKING FIDDLE
You need to add overflow:auto
so that it scrolls if the content overflows the container.
.class {
...
overflow:auto;
}
http://jsbin.com/kuqaqumude/1/edit?html,css,output
For more details concerning overflow: auto
and overflow: visible
,
see:
http://www.w3.org/TR/CSS21/visufx.html#overflow-clipping
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With