简体   繁体   中英

html element background color not showing in IE 8

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

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:

只有一个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.

Not even sure what might be causing the bug.

The problem is the following property in your CSS:

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

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

What happens when you insert this code into your 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; background-color: red; background-color: blue; would result in a blue background color.

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

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

Internet Explorer支持6digit颜色代码,而不是#fff ..使用#ffffff我希望你能理解这一点

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM