Div 100% height scroll
Asked Answered
E

4

42

At my page i have a navigation bar to the left that is 100% height and 25% width. It is working fine, but when there's scroll available, it destroys the background, and make it look ugly. The reason i think is that 100% height is only applied to the active window. What is the trick to have a div 100% height always, even if the user is scrolling?

Css of the navigation:

    width:25%;
    height:100%;
    float:left;
    color:#999999;

I have tried position:absolute with no results, also tried clear both. Need help :)

Fiddle

Edla answered 3/11, 2013 at 20:50 Comment(0)
U
71

Using min-height: 100% instead of height: 100% should fix it. See updated fiddle here: http://jsfiddle.net/zitrusfrisch/Sa6cb/3/

Unbrace answered 3/11, 2013 at 21:4 Comment(3)
This seems to work, but when I do this, I lose the scrolling on the sidenav, which was something I would have liked to keep. Anyone got any ideas on this?Cowhide
I guess we'll never knowFirebox
Setting min-height: 100% and height: auto worked for me, when the content exceeded the height of the viewport.Devinne
M
3

if you want the element to take 100% of the screen use min-height: 100vh and if you want it to take 100% of the parent element use min-height: 100%

Milestone answered 24/4, 2020 at 2:54 Comment(1)
Thanks! Been searching for awhile and the vh units got me what I needed!Psychopathology
E
2

I would rather use:

   height: 100%;
   overflow: auto;
Edaphic answered 6/1, 2022 at 3:36 Comment(0)
G
0

I had a similar issue when I wanted to build an opaque overlay on top of a webpage. The overlay only covered the height of the browser window, not the total scrolling height of the page. I turned to Javascript to dynamically get the page height.

$('body').append('<div style="width:100%;height:'+document.documentElement.scrollHeight+'px;background:#000000;opacity:0.5;position: absolute;top: 0;z-index: 1000;"></div>')
Gillenwater answered 15/3, 2020 at 15:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.