最小高度:100%不适用于IE8(可能还有其他版本)



我正在尝试创建一个由3个部分组成的页面,每个部分的高度都是窗口/视口的100%。我找到了一种可以在Chrome、Firefox(至少是新版本)和Safari中使用的方法。然而,它在IE8(可能还有其他版本)中不起作用。

这是测试页面:http://dev.manifold.ws/test3/

这是HTML:

<body>
    <section id="section1">
    </section>
    <section id="section2">
    </section>
    <section id="section3">
    </section>
</body>

这是CSS:

#section1 {
    min-height:100%;
    position:relative;
    background:#fc1b59;
}
#section2 {
    min-height:100%;
    position:relative;
    background:#d5ea27;
}
#section3 {
    min-height:100%; 
    position:relative;
    background:#0048ff;
}

有人会有跨浏览器的解决方案吗?(至少是主要的更新浏览器)谢谢

-Thom

您需要为HTML5添加IE javascript shiv,并将所有HTML5元素声明为BLOCK元素。

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

考虑使用这个重置CSS文件作为基础:

http://meyerweb.com/eric/tools/css/reset/

首先,IE8不知道<section>(HTML5)标签,需要添加一些JS:

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

(来源)

其次,您需要指定IE8 <section>是一个块:

section {
    display: block;
}

这是一个正在工作的JsFiddle

最新更新