According to the browser adaptive div height, after I set the height to a percentage, it is still invalid

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        -sharpdd {
            width: 100%;
            height: 100%;
        }
        -sharpdd1 {
            width: 20%;
            height: 20%;
            background-color: -sharpF17A7A;
        }
    </style>
</head>
<body>

<div id="dd">
    <div id="dd1">
        111
        222
        2222
    </div>
</div>

</body>
</html>
Apr.02,2021

dom the css style of the object inherits its parent, so the height of html,body needs to be set to 100% so that the height of div can be 100% adaptive.


html,body {

height: 100%;
width: 100%;

}


-sharpdd {
            width: 100vw;
            height: 100vh;
        }
        -sharpdd1 {
            width: 20vw;
            height: 20vh;
            background-color: -sharpF17A7A;
        }

you can try vh

Menu