Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DIV - Force height 100%=/= page height?

Tags:

html

css

height

I am in a big of an issue here with a design I am trying to set up. Here is the website for a reference;

http://throwbackhero.com/index1.php

The problem is that I set the body to height: 100%; in the stylesheet and on the #wrapper div as well. The height goes off the current page height and does not take into account that there are other divs that could cause overflow.

I would like, a blank page to be the size of the browser even if the vertical size of the browser is changed, the content/wrapper div will shrink to accommodate.

Can this be done?

EDIT

Okay so clearly my original question was extremely confusing. Here is a picture;

image

So, in pic 1 (the left) is the issue. With height 100%; on the wrapper and content divs, it is creating that bad boy. I want it to look like picture, where the white/gray area grows/shrinks depending on the size of the browser...

like image 672
Konzine Avatar asked Mar 16 '12 09:03

Konzine


People also ask

Why is height 100% not working HTML?

Setting min-height to 100% on both elements does not allow the body element to fill the page like you might expect. If you check the computed style values in dev tools, the body element has a height of zero. Meanwhile, the HTML element has a height equal to the visible part of the page in the browser.

What does height 100 do in 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.

What does min-height 100% do?

You could consider min-height: 100vh; . This sets the height equal or greater to the size of the screen, vh: vertical height .


2 Answers

The easiest way is simply using CSS:

height: 100vh;

Where 'vh' stands as vertical height of the browser window. Responsive to resizing of brower and mobile devices.

like image 194
alchuang Avatar answered Sep 23 '22 12:09

alchuang


Give body,HTML & main DIV height 100%. write like this:

body,html{height:100%;}

.parent{
    min-height:100%;
    width:400px;
    margin:0 auto;
    background:red;
}

Check this http://jsfiddle.net/3VUGt/

like image 23
sandeep Avatar answered Sep 25 '22 12:09

sandeep