为什么 HTML body background-color 不服从边距?

Why doesn't HTML body background-color obey margin?

根据w3,元素的margin是透明的:

我构建了一个非常基本的 HTML 页面:

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Document</title>
    <style>
        body {
            background-color: red;
        }
    </style>
</head>
<body></body>
</html> 

在 Chrome 中,检查器报告 "body" 有 8px 边距:

但是在页面上,空白处充满了背景色! (请注意,我的书签栏和红色背景之间没有 space - 我保证我没有滚动。

这是怎么回事?

CSS specification特例吧。

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.

...大概是因为人们太习惯了 <body background="#ff0000"> 过去的糟糕日子。