简体   繁体   English

将body和html的高度设置为100%的目的

[英]purpose of setting height to 100% for body and html

<style>
html, body {
    height: 100%;
}

img.one {
    height: auto;
    width: auto;
}

img.two {
    height: 50%;
    width: 50%;
}
</style>

In the css above, when I take out the height property of body and html something seems to happen but I don't understand what. 在上面的css中,当我取出body和html的height属性时,似乎发生了一些事情,但是我不明白是什么。 What is the purpose of setting the height to 100% for body and html? 将body和html的高度设置为100%的目的是什么?

Add border to see the differences. 添加边框以查看差异。

html, body {
    height: 100%; /* Ex: Change it 100% to %75 */
    border: 2px solid red;
}

When you done you can remove the line. 完成后,您可以删除该行。

If you remove the height from html, body then img.two { height: 50%; } 如果您从html, body删除高度html, body img.two { height: 50%; } img.two { height: 50%; } has no reference height any more. img.two { height: 50%; }不再有参考高度。 50% of what should it then be? 那应该是50%

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM