出于好奇,考虑下面的示例,为什么在#container div上留有空白会导致垂直滚动条出现在浏览器中?容器的高度比设置为100%的主体高度小得多。
我已将#container以外的所有元素的填充和边距设置为0。请注意,我故意省略了#container div上的绝对定位。在这种情况下,浏览器如何计算身体的高度,边距对其有何影响?
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
* { padding:0; margin:0;}
html, body { height:100%; }
#container
{
padding:10px;
margin:50px;
border:1px solid black;
width: 200px;
height: 100px;
}
</style>
</head>
<body>
<div id='container'>
</div>
</body>
</html>