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

前端 未结 1 698
抹茶落季
抹茶落季 2020-12-21 09:17

According to w3, the margin of an element is transparent:

I\'ve built a very basic HTML page:




        
相关标签:
1条回答
  • 2020-12-21 09:47

    The CSS specification special cases it.

    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.

    … presumably because people were too used to <body background="#ff0000"> from the bad old days.

    0 讨论(0)
提交回复
热议问题