min-height does not work with body

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)

61983 次浏览

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%}

Not all browsers like min-height, try something like this to catch all browsers.

  min-height:100%;
height:auto !important;
height:100%;
html{
height:100%;
}
body{
min-height:100%;
position:relative;
}

you must add

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

html {
min-height: 100%;
display: flex;
}


body {
flex: 1;
}

I solved the problem with just:

body {
min-height: 100vh;
}

None of the above answers work for me.

What I did:

html, body {
height: 100%;
display: grid;
}