2

我在页面中有 header1 div,我想设置位置:在 IE7 和 IE6 中固定顶部和中心。在多分辨率。

EX 分辨率

EX 分辨率

我在 css 中使用此代码:

.page
{
width:900px;
    height:auto;
    margin:auto;
}
.header1
{
width: 500px;
height: 60px;
float: right;
position: fixed;
display: block;
z-index: 1100; 
margin: 0 50px 0 0;
}

html代码:

<div class="page">
<div class="header1"></div>
</div>

或者

.page
{
width:900px;
    height:auto;
    margin:auto;
}
.header1
{
width: 500px;
height: 60px;
float: right;
position: fixed;
display: block;
z-index: 1100; 
top: 0px;
    right: 0px; /*right: X px*/
    left: 0px; /*left: X px*/
}

html代码:

<div class="page">
<div class="header1"></div>
</div>

它适用于 IE 8+,.. 但不适用于 IE7 和 6。

4

5 回答 5

4

IE6 不支持position:fixed

IE7确实支持它,但有错误。

最终,您将无法使用纯 CSS 来完成这项工作。您可能可以使用 javascript polyfill 脚本使其工作,该脚本将更新的浏览器功能添加到旧的 IE 版本。

我知道的唯一包含此功能的 polyfill 脚本是ie7.js / ie8.js /ie9.js。该脚本为旧 IE 版本添加了一大堆额外功能,包括position:fixed. 它并不完美,但它可能对你有用。

希望有帮助。

您可以在此处找到有关浏览器支持的更多信息:http: //quirksmode.org/css/css2/

于 2013-08-13T20:47:03.537 回答
1

我不担心IE 6或IE7,IE 8、9和10用得更多,这只是一部分互联网用户并不真正担心互联网,我们其他人使用Firefox,Opera和铬合金。

于 2013-08-30T12:58:20.937 回答
1

在页面顶部添加 DocType 标签

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
于 2013-08-13T20:38:37.797 回答
1

我有类似的问题,但尝试

.page
{
width:900px;
height:auto;
margin:auto;
padding:0pt

}

这可能会导致您放置更多的 CSS 以获得更少的效果,IE6 可能是个问题。

于 2013-08-27T15:24:00.687 回答
1

position:fixed 应该给父容器而不是子容器

这是你要的吗

.page
{
 width:100%;
 position: fixed;
 top: 0px;   

}
.header1
{
 width: 500px;
 margin: 0 auto;
 height: 60px;
}
于 2013-08-28T11:51:17.517 回答