在html与body上设置背景颜色的权衡? [英] Tradeoffs of setting background-color on html vs. body?

查看:227
本文介绍了在html与body上设置背景颜色的权衡?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果在我的CSS中我设置了background-color属性在body

元素上,它仅涵盖

正文中定义的元素的背景,直到页面的当前宽度和高度。但是,如果

当前组件集的高度较小,则会留下原始背景颜色(白色)的页面大部分b $ b。


但是,如果我在html上设置属性相反,它会使整个可见页面的颜色变为
,超出页面上所有

组件的当前高度。


后者似乎对我来说效果会更好,但是我很想知道这样做有什么不利之处。


这可能不会在真实的页面上产生那么大的差异,因为我的

当前页面只是一个测试JavaScript组件的页面我是

整合。它集成的真实页面将有更多的b / b
信息,这样初始页面高度将比

初始可见区域更长。

If in my CSS I set the "background-color" property on the "body"
element, it only covers the background of the elements defined in the
body, up to the current width and height of the page. However, if the
current component set has a resulting small height, this leaves most
of the page with the original background color (white).

However, if I set the property on the "html" element instead, it does
color the entire visible page, beyond the current height of all the
components on the page.

The latter seems like it''s going to work better for me, but I''m
wondering if there are any disadvantages of doing this.

This probably won''t make that much difference on a real page, as my
current page is just a page to test the JavaScript components I''m
integrating. The real page it gets integrated into will have much more
information, such that the initial page height will be longer than the
initial visible area.

推荐答案

david.karr写道:
david.karr wrote:

如果在我的CSS中我设置了background-color属性在body

元素上,它仅涵盖

正文中定义的元素的背景,直到页面的当前宽度和高度。但是,如果

当前组件集具有较小的高度,则会留下具有原始背景颜色(白色)的页面的大部分

If in my CSS I set the "background-color" property on the "body"
element, it only covers the background of the elements defined in the
body, up to the current width and height of the page. However, if the
current component set has a resulting small height, this leaves most
of the page with the original background color (white).



什么是当前组件集如果它有一个

产生的小高度是什么意思?

What is "current component set" and what does it mean for it to have a
"resulting small height"?


>

但是,如果我在html上设置属性。相反,它会使整个可见页面的颜色为
,超出页面上所有

组件的当前高度。
>
However, if I set the property on the "html" element instead, it does
color the entire visible page, beyond the current height of all the
components on the page.



如果身体有保证金,那么你当然希望为html

着色,除非你想要身体的保证金拥有浏览器的默认颜色。

If the body has a margin, then you certainly do want to color the html
unless you want the body''s margin to have the browser''s default color.


8月19日,12:12 * pm,Harlan Messinger

< hmessinger.removet。 .. @ comcast.netwrote:
On Aug 19, 12:12*pm, Harlan Messinger
<hmessinger.removet...@comcast.netwrote:

david.karr写道:
david.karr wrote:

如果在我的CSS中我设置背景颜色属性在body

元素上,它仅涵盖

正文中定义的元素的背景,直到页面的当前宽度和高度。但是,如果

当前组件集具有较小的高度,则会留下具有原始背景颜色(白色)的页面的大部分

If in my CSS I set the "background-color" property on the "body"
element, it only covers the background of the elements defined in the
body, up to the current width and height of the page. However, if the
current component set has a resulting small height, this leaves most
of the page with the original background color (white).



什么是当前组件集如果它有一个

产生的小高度是什么意思?


What is "current component set" and what does it mean for it to have a
"resulting small height"?



我的测试页面定义了两个div,其中一个最初是填充的,

而另一个是空的。唯一填充的div约为100像素

高。页面的其余部分为空白。在html元素上设置background-color或

body元素之间的

结果有很大的不同。

My test page defines two divs, one of which is initially populated,
and the other is empty. The only populated div is about 100 pixels
high. The rest of the page is blank. There''s a big difference in the
result between setting background-color on the html element or the
body element.


但是,如果我在html上设置属性相反,它会使整个可见页面的颜色为
,超出页面上所有

组件的当前高度。
However, if I set the property on the "html" element instead, it does
color the entire visible page, beyond the current height of all the
components on the page.



如果身体有保证金,那么你当然希望为html

着色,除非你想要身体的保证金拥有浏览器的默认颜色。


If the body has a margin, then you certainly do want to color the html
unless you want the body''s margin to have the browser''s default color.



我想控制整个可见页面的背景颜色。


请注意,当我搜索类似的问题时这个,我发现声明

说它不建议在html

元素上设置背景颜色,而不是body元素。然而,他们并没有说出为什么。

I want to control the background-color on the entire visible page.

Note that when I googled for questions like this, I found statements
that say it''s not recommended to set background-color on the html
element, as opposed to the body element. They didn''t say WHY, however.


david.karr写道:
david.karr wrote:

我想要控制整个可见页面上的背景颜色。


请注意,当我搜索这样的问题时,我发现声明

表示它不是建议在html

元素上设置背景颜色,而不是body元素。然而,他们并没有说出为什么。
I want to control the background-color on the entire visible page.

Note that when I googled for questions like this, I found statements
that say it''s not recommended to set background-color on the html
element, as opposed to the body element. They didn''t say WHY, however.



也许这与以下事实有关:现在已经灭绝的一些旧版浏览器不支持应用于HTML的CSS元素。

Perhaps this is related to the fact that that some legacy browsers,
which are now extinct, did not support CSS applied to the HTML element.


这篇关于在html与body上设置背景颜色的权衡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆