Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Div 100% height scroll

Tags:

css

height

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

like image 825
simon Avatar asked Nov 03 '13 20:11

simon


People also ask

How do you give a Div 100 height?

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.

What does height 100% do CSS?

height: 100% gives the element 100% height of its parent container. height: auto means the element height will depend upon the height of its children.

How do I get total scroll height?

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.

What is scroll height?

The scroll height refers to the entire height of that element in the HTML page, even if it is not viewable due to overflow property. The element's scroll height includes the height assigned in CSS property plus the padding, but it does not include the margin, border, or scrollbar.


2 Answers

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

like image 75
Daniel Riemer Avatar answered Sep 21 '22 09:09

Daniel Riemer


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%

like image 31
Alex Quintero Avatar answered Sep 21 '22 09:09

Alex Quintero