Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DIV - 100% height causing scroll bars

Tags:

html

css

I am having a bit of issue with a div causing scroll bars when height set to 100%.

Right now, my page content looks like;

<body>  

<hr>

<div id="content">

    <div id="heading">

    </div>

</div>


</body>

The problem is that the HR is 5px, and the Content is 100% of body height. So, since it is 100% of page height, it is going below the HR and creating 5px so that a scrollbar is being made which I want to avoid..

My question is, how do I make it height 100% without it thinking that it needs to be 100%pageheight and not including the HR in the page height?

Thanks.

like image 541
Konzine Avatar asked Mar 09 '12 17:03

Konzine


People also ask

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 make my Div 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.

Why does 100vh overflow?

Why does 100vh Issue Happen on Mobile Devices? I investigated this issue a bit and found out the reason. The short answer is that the browser's toolbar height is not taken into account. If you want to go deep on why this happens, I found this Stack Overflow thread very helpful.


3 Answers

This kind of layout is best accomplished using absolute positioning. Here's an example, using your HTML: http://jsfiddle.net/7KGmZ/

css:

#content
{
    position: absolute;
    top: 20px;
    right: 0px;
    bottom: 0px;
    left: 0px;
}​
like image 182
Hubro Avatar answered Sep 20 '22 16:09

Hubro


You can try:

position: absolute;
top: 0px;
bottom: 0px;

This will however overlap over the HR. If you set the top position to 5px, it won't.

like image 38
t0nyh0 Avatar answered Sep 19 '22 16:09

t0nyh0


  • You could remove the hr and put a border on the heading div.
  • You could remove the hr and put a border on the content div and change the box-sizing property to border-box.
  • You could move the hr inside the content div.
like image 31
Joel Avatar answered Sep 20 '22 16:09

Joel