Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

min-height does not work with body

Tags:

html

css

Does min-height not work on body/html?

body, html {     min-height:100%; } 

Accomplishes absolutely nothing (firebug reports the body,html tags height does not change at all)

like image 454
Razor Storm Avatar asked Sep 18 '10 07:09

Razor Storm


People also ask

Should I use height or min height?

The difference between height and min-height is that height defines a value for the height and that's how tall the element will be. min-height says that the minimum height is some value but that the element can continue to grow past that defined height if needed (like the content inside makes it taller or whatever).

Why is height percentage not working?

If set relatively, element's height will be relative to the height of the parent — if set. If the height of parent is not set — the height of the element will stay auto (like: 50% from auto is auto). That is why relative values of height usually don't work — because certain conditions must be met beforehand.

What is default height of body?

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. The body element has a default 8px margin indicated by the bar on top.

Why do we use min height?

The CSS min-height property applies to block level and replaced elements. The CSS min-height property is used to prevent the CSS height from becoming smaller than the value specified in the CSS min-height property. When the value is provided as a percentage, it is relative to the height of the containing block.


2 Answers

First, declare a doctype so you're in standards if you haven't already.

Now, the body can only be as high as the containing html, so you need to set HTML tag to 100% height, and body to min-height 100%. This works for me on Firefox.

html {height:100%}  body {min-height:100%} 
like image 71
Moses Avatar answered Oct 18 '22 18:10

Moses


This worked for chrome 64 without setting a hard-coded height:

html {     min-height: 100%;     display: flex; }  body {     flex: 1; } 
like image 28
Guy Avatar answered Oct 18 '22 19:10

Guy