Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create scrollable content for a fixed 100% height div

I would like to create a scrollable div. I know here is lots of example, but neither of them works for me.

I have a .page class, which fills my mobile's screen. Inside of it I have a .content div. This is contain the content of the pages. It is just align the content from the top, and it should have to scroll the content if it is going out of the .content's boundaries.

.page{
    margin: 0;
    padding: 0;
    min-height: 100%;
    width: 100%;
    display: block;
}
.content{
    padding: 4em 0 0 0;
    overflow-x: hidden;
    overlofw-y: auto;
    /*-webkit-overflow-scrolling: touch;*/    
}

What should I do to get it working?

Update

I tried it in fiddle, and it is worked. But not on my phone. Because of it I don't know where should be the problem.

Because of it I attached my whole code to the question. This is very important for me to get it working.

Please help me. Thanks for any help. :)

like image 688
Gábor Avatar asked May 27 '13 11:05

Gábor


People also ask

How do I keep my div fixed when scrolling?

The interesting rule here is the ' position: fixed ', that makes the DIV stay fixed on the screen. The ' top: 50% ' and ' right: 0 ' determine where the DIV is displayed, in this case: 50% down from the top of the window, and a constant 0px from the right.

How do I make a div content 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.

How do I set the height of a div to 100?

Syntax: To set a div element height to 100% of the browser window, it can simply use the following property of CSS: height:100vh; Example: HTML.

How do I get the scroll height of a div?

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.


1 Answers

Is this what you need??

html, body{
    height:100%;
    margin:0;
    padding:0;
}
.page{
    margin: 0;
    padding: 0;
    height: 100%;
    width: 50%;
    display: block; border:solid #000 1px
}
.content{
    padding:0;
    overflow: scroll; overflow-x:hidden;
    height:100%
    /*-webkit-overflow-scrolling: touch;*/    
}
span{
     padding:4em 0 0 0;
    display:inline-block
}

DEMO

Use span tag to specify the padding for content div coz if you give padding to the content div it calculates as additional height 100%+4em so..

And make sure that you are specifying html and body height as 100% whenever you want to use height:100% in your page.

like image 167
Sowmya Avatar answered Nov 03 '22 01:11

Sowmya