【问题标题】:Fixed page layout in IE6修复了 IE6 中的页面布局
【发布时间】:2020-07-20 07:43:46
【问题描述】:

页眉、页脚和侧边栏有固定的位置。在中心有两个滚动条的内容区域。浏览器上没有外部滚动条。我有一个适用于 IE7 和 FF 的布局。我需要添加 IE6 支持。我怎样才能做到这一点?

这是我当前 CSS 的近似值。

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    
    <head>
      <title>Layout</title>
      <style>
        * {
          margin: 0px;
          padding: 0px;
          border: 0px;
        }
        
        .sample-border {
          border: 1px solid black;
        }
        
        #header {
          position: absolute;
          top: 0px;
          left: 0px;
          right: 0px;
          height: 60px;
        }
        
        #left-sidebar {
          position: absolute;
          top: 65px;
          left: 0px;
          width: 220px;
          bottom: 110px;
        }
        
        #right-sidebar {
          position: absolute;
          top: 65px;
          right: 0px;
          width: 200px;
          bottom: 110px;
        }
        
        #footer {
          position: absolute;
          bottom: 0px;
          left: 0px;
          right: 0px;
          height: 105px;
        }
        
        @media screen {
          #content {
            position: absolute;
            top: 65px;
            left: 225px;
            bottom: 110px;
            right: 205px;
            overflow: auto;
          }
          body #left-sidebar,
          body #right-sidebar,
          body #header,
          body #footer,
          body #content {
            position: fixed;
          }
        }
      </style>
    </head>
    
    <body>
      <div id="header" class="sample-border"></div>
      <div id="left-sidebar" class="sample-border"></div>
      <div id="right-sidebar" class="sample-border"></div>
      <div id="content" class="sample-border"><img src="/broken.gif" style="display: block; width: 3000px; height: 3000px;" /></div>
      <div id="footer" class="sample-border"></div>
    </body>
    
    </html>

【问题讨论】:

    标签: html css xhtml internet-explorer-6


    【解决方案1】:

    对于您的项目来说可能有点过头了,但是Dean Edwards' IE7 javascript adds support for fixed positioning to IE6

    【讨论】:

      【解决方案2】:

      将以下代码添加到&lt;head&gt;

      <!--[if lte IE 6]>
      <style type="text/css">
      html, body {
          height: 100%;
          overflow: auto;
      }
      .ie6fixed {
          position: absolute;
      }
      </style>
      <![endif]-->
      

      ie6fixed CSS 类添加到您想成为的任何position: fixed;

      【讨论】:

        【解决方案3】:

        试试 IE7.js。无需进行任何修改即可解决您的问题。

        链接:IE7.js

        【讨论】:

          【解决方案4】:

          这些答案很有帮助,它们确实让我向 IE6 添加了有限形式的固定定位,但是如果我为侧边栏指定顶部和底部 css 属性,这些都不能修复破坏我在 IE6 中的布局的错误(这是我需要的行为)。

          由于无法指定顶部和底部,因此我使用了顶部和高度。事实证明,高度属性是非常必要的。我使用 javascript 重新计算页面加载时的高度以及任何调整大小。

          下面是我添加到测试用例中以使其工作的代码。使用 jQuery 可能会更干净。

          <!--[if lt IE 7]>
          <style>
          body>div.ie6-autoheight {
            height: 455px;
          }
          body>div.ie6-autowidth {
            right: ;
            width: 530px;
          }
          </style>
          <script src="http://ie7-js.googlecode.com/svn/version/2.0(beta3)/IE7.js" type="text/javascript"></script>
          <script type="text/javascript">
          
          function fixLayout() {
             if (document.documentElement.offsetWidth) {
                var w = document.documentElement.offsetWidth - 450;
                var h = document.documentElement.offsetHeight - 175;
                var l = document.getElementById('left-sidebar');
                var r = document.getElementById('right-sidebar');
                var c = document.getElementById('content');
          
                c.style.width = w;
                c.style.height = h;
                l.style.height = h;
                r.style.height = h;
             }
          }
          window.onresize = fixLayout;
          fixLayout();
          </script>
          <![endif]-->
          

          【讨论】:

            【解决方案5】:

            查看下面的纯 css hack...有些需要强制它进入 quirks 模式(我认为这是最强大的),但一切都很好:

            http://ryanfait.com/resources/fixed-positioning-in-internet-explorer/ http://tagsoup.com/cookbook/css/fixed/

            我用这个效果很好,希望对你有帮助!

            【讨论】:

              猜你喜欢
              • 2017-01-29
              • 2010-09-10
              • 2011-09-22
              • 2012-06-23
              • 1970-01-01
              • 1970-01-01
              • 2014-10-30
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多