html 元素背景颜色未在 IE 8 中显示

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5345446/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 07:26:10  来源:igfitidea点击:

html element background color not showing in IE 8

htmlcssinternet-explorerinternet-explorer-8background-color

提问by Donald Jenkins

I'm using the <body>tag as a wrapper for three divs on a site where every single background color is white.

<body>在一个网站上使用标签作为三个 div 的包装器,其中每个背景颜色都是白色。

I've set the background color to #fff for the html and body in the css, and the site is rendering correctly in every browser (including IE 6 and 7) except IE8:

我已将 css 中的 html 和 body 的背景颜色设置为 #fff,并且该站点在除 IE8 之外的每个浏览器(包括 IE 6 和 7)中都能正确呈现:

Only one of the divs (the central content) is displaying its background color

只有一个 div(中心内容)显示其背景颜色

I've even tried setting the style for html directly inline like so: <html style="background-color: #fff">but that doesn't seem to change anything.

我什至尝试过像这样直接内联设置 html 的样式:<html style="background-color: #fff">但这似乎没有改变任何东西。

Not even sure what might be causing the bug.

甚至不确定是什么导致了这个错误。

采纳答案by Stephan Muller

The problem is the following property in your CSS:

问题在于您的 CSS 中的以下属性:

:focus{
  outline:0;
  background-color:#f2f3f6;
  border-color:#996
}

Apparently, on loading IE8 decides that the htmlelement has focus, whereas other browsers don't do this. Remove the background-color property here and it'll all stay white.

显然,在加载 IE8 时决定html元素具有焦点,而其他浏览器不这样做。删除这里的 background-color 属性,它会全部保持白色。

回答by Blender

What happens when you insert this code into your HTML?

将此代码插入 HTML 时会发生什么?

body div
{
  background-color: white !important;
}

Normally, browsers interpret and apply the last line of CSS that they read to an element, so background-color: red; background-color: blue;would result in a blue background color.

通常,浏览器会解释并将它们读取的最后一行 CSS 应用于元素,因此background-color: red; background-color: blue;会导致背景颜色为蓝色。

!importanttell the browser to ignore all other property re-decelerations, so background-color: red !important; background-color: blue;would make the background color red, even though you told it to be blue.

!important告诉浏览器忽略所有其他属性的重新减速,因此background-color: red !important; background-color: blue;会使背景颜色为红色,即使您告诉它为蓝色。

回答by Krishna

I think background:#FFFFFF;will fix it. It worked for me.

我认为background:#FFFFFF;会解决它。它对我有用。

回答by MFarooqi

internet explorer support 6digit color code i.e. instead of #fff .. use #ffffff I hope you may understand this

Internet Explorer 支持 6 位颜色代码,即代替 #fff .. 使用 #ffffff 我希望你能理解这一点