Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7972473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:52:42+00:00 2026-06-04T07:52:42+00:00

The following code works properly <!DOCTYPE html> <html> <head> <title>Working</title> <style type=text/css> html {

  • 0

The following code works properly

<!DOCTYPE html>
<html>
<head>
<title>Working</title>
<style type="text/css">
html {
  height: 100%;
}
body {
  height: 100%; /* !!!!! difference in here */
}
div#main {
  min-height: 100%;
  background-color: red;
}
</style>
</head>
<body>
    <div id="main"></div>
</body>

while a code using min-height instead of height for body prevents #main from occupying space

<!DOCTYPE html>
<html>
<head>
<title>Not working</title>
<style type="text/css">
html {
  height: 100%;
}
body {
  min-height: 100%; /* !!!!! difference in here */
}
div#main {
  min-height: 100%;
  background-color: red;
}
</style>
</head>
<body>
    <div id="main"></div>
</body>

Weird thing is when doing an inspect in chrome, in both cases body properly takes up 100% space. In min-height case however the child element min-height: 100%; translates to 0. Why does it happen and is there any workaround? I would like the min-height for my web page for background to work properly and expand as needed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:52:43+00:00Added an answer on June 4, 2026 at 7:52 am

    As to “Why does it happen?”

    The min-height property only works if an explicit height is set. The spec reads for a percentage:

    Specifies a percentage for determining the used value. The percentage
    is calculated with respect to the height of the generated box’s
    containing block. If the height of the containing block is not
    specified explicitly (i.e., it depends on content height), and this
    element is not absolutely positioned, the percentage value is treated
    as ‘0’ (for ‘min-height’) or ‘none’ (for ‘max-height’).

    The key point in that is that “If the height of the containing block is not
    specified explicitly (i.e., it depends on content height).” When body is set with min-height, it is still depending on content height for calculation, only it does not allow it to fall below the specified size (in your case, 100% of html height which is explicitly set). However, because body is still depending on content to set its height, then div#main cannot calculate min-height because body does not have an explicit height set.

    Is a “Workaround” Needed?

    It seems that setting body to height: 100% achieves all you want. Whether content is long or content is short.

    Response to Comment on html change of background-color

    I suspect the reason your fiddle with html having background-color set changes things is because of the notations in this spec (quoted below). By setting that on html it changes the canvas rendering itself:

    The background of the root element becomes the background of the
    canvas and covers the entire canvas, anchored (for
    ‘background-position’) at the same point as it would be if it was
    painted only for the root element itself. The root element does not
    paint this background again.

    For HTML documents, however, we recommend that authors specify the
    background for the BODY element rather than the HTML element. For
    documents whose root element is an HTML “HTML” element or an XHTML
    “html” element that has computed values of ‘transparent’ for
    ‘background-color’ and ‘none’ for ‘background-image’, user agents must
    instead use the computed value of the background properties from that
    element’s first HTML “BODY” element or XHTML “body” element child when
    painting backgrounds for the canvas, and must not paint a background
    for that child element. Such backgrounds must also be anchored at the
    same point as they would be if they were painted only for the root
    element.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

following code works properly but it applies same cell text to all sections. How
The following code works fine: person = {:a=>:A, :b=>:B, :c=>:C} berson = {:a=>:A1, :b=>:B1,
The following code works as expected on CentOS and Ubuntu O/s but not on
The following code works, but I can't figure out what's going on memory-wise. Where
The following code works fine for Visual C++ 2008. However, when comes to Visual
The following code works fine #define open { #define close } #include<stdio.h> #define int
The following code works with Visual Studio 2008 but not with GCC/G++ 4.3.4 20090804.
The following code works fine : std::map<int, int>& m = std::map<int, int>(); int i
The following code works, but I'm curious as to why I need the Path
The following code works: @Stateless @LocalBean public class MyClass { @PersistenceContext(name = MyPU) EntityManager

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.