IE8没有正确显示定位div

时间:2013-03-12 20:11:31

标签: css internet-explorer-8 z-index

我在IE8中的布局方面遇到了一些问题。我有一个很大的背景图像。然后我希望我的标题详细信息位于此之上。我使用z-index的绝对定位让它坐在上面。所有其他浏览器都很完美,只有IE8给我带来了问题。它将我的标题放在大图像下方。

这是我的代码

<div id="homepage-banner">
     <img class="home-carousel" src="images/banner.jpg" />
</div>
              <header>
                    <div id="logo">
                            <img src="images/logo.png" />
                    </div>

                    <div id="header-text">
                            <p><span style="font-weight:bold; color: white">></span> Call us now on <strong>0800 785 7348</strong></p>
                            <p><span style="font-weight:bold; color: white">></span> <a href="#"  style="font-weight: bold; text-decoration: none; color: black">Click here</a> to enquire online</p>
                    </div>

                    <div id="nav-bar">
                            <img src="images/nav.png"  width="980" height="45"/>
                    </div>
            </header> <!-- header -->

我的CSS

header {
    height: 120px;
    width: 980px;
    z-index: 1000;
    position: absolute;
    top: 25px; }


#homepage-banner {
    height: 555px;
    width: 3000px;
    margin-left: -1000px;
    margin-bottom: -210px;
    background-color: rgb(0,173,239); }

如何更改我的代码,以便IE8在图像顶部显示我的标题?

1 个答案:

答案 0 :(得分:2)

我假设您没有包含shiv脚本,因为IE 8支持z-index。因为您使用HTML 5 <header>元素而不包含html5shiv脚本,IE无法正确解析标题,导致您描述的行为。只需按照我提供的链接,在<head>中包含该脚本,您就可以获得对新HTML 5元素的支持..

将其放入<head>

中的条件评论中
<!--[if lt IE 9]>
 <script src="dist/html5shiv.js"></script>
<![endif]-->