微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

与身体相比,将CSS规则应用于html有什么区别?

我看不出区别:
html {
    background: #f1f1f1;
}

body {
    background: #f1f1f1;
}

任何解释?

解决方法

没有什么真正的区别(如果你只是在说应用背景的地方,否则 BoltClock’s answer to this other question更适合)。 html是一个元素,就像身体一样。

两者都是有效的选择,两者都可以在所有常见的浏览器中运行。

例如,YUI重置,选择在html元素而不是body设置背景:
http://yui.yahooapis.com/3.3.0/build/cssreset/reset.css

这要求您将背景设置为html,例如:can’t change body background color using CSS reset

参见:http://dev.w3.org/csswg/css3-background/#special-backgrounds

The background of the root element becomes the background of the
canvas and its background painting area extends to cover the entire
canvas,although any images are sized and positioned relative to the
root element as if they were painted for that element alone. (In other
words,the background positioning area is determined as for the root
element.) If the root’s ‘background-color’ value is ‘transparent’,the
canvas’s background color is UA dependent. The root element does not
paint this background again,i.e.,the used value of its background is
transparent.

和:

For documents whose root element is an HTML HTML element [HTML401] or
an XHTML html element [XHTML11]: if the computed value of
‘background-image’ on the root element is ‘none’ and its
‘background-color’ is ‘transparent’,user agents must instead
propagate the computed values of the background properties from that
element’s first HTML BODY or XHTML body child element. The used values
of that BODY element’s background properties are their initial values,
and the propagated values are treated as if they were specified on the
root element. It is recommended that authors of HTML documents specify
the canvas background for the BODY element rather than the HTML
element.

在这里展示了这个文字的墙壁:

>身体背景:http://jsfiddle.net/hhtzE/
> html和body的背景:http://jsfiddle.net/hhtzE/1/
> background only html:http://jsfiddle.net/hhtzE/2/

原文地址:https://www.jb51.cc/css/218561.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。