css - 背景 : color does not work in IE8

标签 css

body {
    background: gray; 
    font-family: sans-serif;
    width: 960px;
    margin: auto;
}

header {
    background: green;
    border: 10px solid black;
}

nav {
    margin-top:10px;
    background: #62D99C;
    border-radius: 10px;
    padding: 10px;
}

页眉和导航背景在 IE8 中不工作。它确实适用于 Chrome 和 FF。我应该怎么办? 谢谢!

最佳答案

您应该将 display:block 应用于标题和导航元素:

header {
  display: block;
  background: green;
  border: 10px solid black;
}

nav {
  display: block;
  margin-top:10px;
  background: #62D99C;
  border-radius: 10px;
  padding: 10px;
}

看来你还需要包含以下js:

<!--[if lt IE 9]>
<script>
  document.createElement('header');
  document.createElement('nav');
</script>
<![endif]-->

可以在这里找到原因:

http://tatiyants.com/how-to-get-ie8-to-support-html5-tags-and-web-fonts/

简而言之,默认情况下,IE8 不支持 HTML5 元素,但通过执行此 javascript (仅适用于 IE8 或更低版本),它开始识别这些元素。大多数开发人员使用某种形式的 html5 shim 来解决这个问题。

http://code.google.com/p/html5shim/

关于css - 背景 : color does not work in IE8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13439831/

相关文章:

javascript - mdl-stepper javascript 和 HTML

html - 我如何将我的 (html) 登录页面和其他页面链接到我的索引页面

javascript - 单击按钮如何显示它已被选中并在表单提交时获取该按钮的 ID

php - 如何在 CodeIgniter 中使用 PHP 根据条件显示表单字段?

html - 我无法将简单的导航栏转换为响应式导航栏

css - 如何将此 css 重写为 xpath

javascript - 根据受欢迎程度缩放内容标签

javascript - 动画导航菜单

html - Bootstrap - 面板周围的白色边框

javascript - 我如何混合使用 addClass Api 和 fadein?