gpt4 book ai didi

html - 当 html 标签没有设置背景颜色时,为什么 body 背景图像不包含在 body 中?

转载 作者:搜寻专家 更新时间:2023-10-31 23:22:51 26 4
gpt4 key购买 nike

谷歌的 404 page使用边距和填充使 body 标签内的内容居中,如下所示:

body {
margin: 7% auto 0;
max-width: 390px;
min-height: 180px;
padding: 30px 0 15px;
}

损坏的机器人的图像然后被设置为 body 标签上的背景图像,并位于右上角,这样它就出现在主要内容的右侧。

* > body {
background: url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;
padding-right: 205px;
}

html 样式如下所示:

html {
background: #fff;
color: #222;
padding: 15px;
}

为什么去除html标签的背景色后,图片出现在页面右上角?

html {
//background: #fff;
color: #222;
padding: 15px;
}

Broken plunkr example

最佳答案

技术原因是“因为 specification 这么说”:

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 元素上的 bgcolorbackground 属性决定的,所以制作了 CSS "与现有实践兼容”。

关于html - 当 html 标签没有设置背景颜色时,为什么 body 背景图像不包含在 body 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37342399/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com