I wrote a piece of css code, but there is a large blank after it. How to solve it?

I want to leave 20px on the div of container, 20px on the header and 20px on the footer, and then the rest of the page is full of container

the right side leaves 20px for right, and the rest is container,. Don"t leave blank

.

now, although I set the height of container to 100%, it still leaves a big blank. What is the reason for this

?

how to modify to make the white space disappear.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>

<style>
div {
    box-sizing: border-box;
}

.header {
    height: 20px;
    background: rgba(51,255,255,1);
}

.container {
    position: relative;
    padding-top: 20px;
    padding-bottom: 20px;
    padding-left: 50px;
    background: rgba(51,0,153,1);
    height: 100%;
}

.right {
    position: absolute;
    right: 0;
    top: 0;
    width: 50px;
    background:rgba(204,0,51,1);
    height: 100%
}

.footer {
    height: 20px;
    background: rgba(153,0,0,1);
}

</style>

</head>

<body>

<div>

    <div class="header"></div>

    <div class="container">
        <div class="list">
            
        </div>
        
        <div class="right">
            <ul>
                <li>111</li>
                <li>222</li>
                <li>333</li>
            </ul>
        </div>
    
    </div>
    
    <div class="footer"></div>

</div>

</body>
</html>

the modified code will still appear a large amount of blank space

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>

<style>

html, body, div, p, ul, li, ol, dl, dt, dd, pre, code, table, tr, td, form, fieldset,
legend, button, input, textarea, h1, h2, h3, h4, h5, h6, hr, blockquote {
    margin: 0;
    padding: 0;
}


div {
    box-sizing: border-box;
}


html {
    height: 100%;
}

.header {
    height: 20px;
    background: rgba(51,255,255,1);
}

.container {
    position: relative;
    padding-top: 20px;
    padding-bottom: 20px;
    padding-left: 50px;
    background: rgba(51,0,153,1);
    height: 100%;
}

.container ul {
    list-style: none;
}

.right {
    position: absolute;
    right: 0;
    top: 0;
    width: 50px;
    background:rgba(204,0,51,1);
    height: 100%
}

.footer {
    height: 20px;
    background: rgba(153,0,0,1);
}

</style>

</head>

<body>

<div>

    <div class="header"></div>

    <div class="container">
        <div class="list">
            
        </div>
        
        <div class="right">
            <ul>
                <li>111</li>
                <li>222</li>
                <li>333</li>
            </ul>
        </div>
    
    </div>
    
    <div class="footer"></div>

</div>

</body>
</html>
Sep.16,2021

height: 100% is relative to the parent element, and if the parent element does not set a height, the actual height of the height: 100% is zero. Here the actual height of the container is equal to 0 + 40px (the height generated above and below the padding).

solution: 100vh can be used instead of 100%

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>

<style>
* {
    padding: 0;
    margin: 0;
}
ul,li{
    list-style: none;
}
div {
    box-sizing: border-box;
}

.header {
    height: 20px;
    background: rgba(51,255,255,1);
}
.container {
    position: relative;
    padding-top: 20px;
    padding-bottom: 20px;
    padding-left: 50px;
    background: rgba(51,0,153,1);
    height: calc(100vh - 40px);
}

.right {
    position: absolute;
    right: 0;
    top: 0;
    width: 50px;
    background:rgba(204,0,51,1);
    height: 100%
}

.footer {
    height: 20px;
    background: rgba(153,0,0,1);
}

</style>

</head>

<body>

<div>

    <div class='header'></div>

    <div class='container'>
        <div class='list'>
            
        </div>
        
        <div class='right'>
            <ul>
                <li>111</li>
                <li>222</li>
                <li>333</li>
            </ul>
        </div>
    
    </div>
    
    <div class="footer"></div>

</div>

</body>
</html>

1. Normally, it won't be like this. Refresh and take a look. Or select the element to see if there is anything else that affects the height of the
2.container. The height should not be set this way, and a scroll bar will appear. Height: calc (100%-40px);-- minus the height of header and footer


reason:
1, height:100% is the height relative to the parent element;
2, the ancestor element of .container does not set the height;
3, the html height is not equal to the window height by default.

solution:
1, add height:100% to all ancestor elements of .container (all ancestor elements starting with the html element);
2, use vh units for compatibility.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e50867-43670.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e50867-43670.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?