代码之家  ›  专栏  ›  技术社区  ›  googletorp

ie6+ie7 css溢出问题:隐藏;-位置:相对;组合

  •  64
  • googletorp  · 技术社区  · 15 年前

    因此,我为主页创建了一个滑块,它使用jquery滑动一些带有标题和摘要文本的图像。一切正常,我去检查IE,发现IE 6和7完全杀死了我的滑盖CSS。我不知道为什么,但是由于某种原因,我不能用overflow:hidden来隐藏非活动的幻灯片;我试着前后调整css,但是还不能找出导致问题的原因。

    我在一个更孤立的html页面中重新创建了这个问题。

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="da" lang="da" dir="ltr">
      <head>
        <style>
          body {
           width: 900px;
          }
          .column-1 {
            width: 500px;
            float: left;
          }
          .column-2 {
            width: 200px;
            float: left;
          }
          .column-3 {
            width: 200px;
            float: left;
          } 
          ul {
            width: 2000px;
            left: -499px;
            position: relative;
          }
    
          li {
            list-style: none;
            display: block;
            float: left;
          }
    
          .item-list {
            overflow: hidden;
            width: 499px;
          }
        </style>
      </head>
      <body>
        <div class="column-1">
          <div class="item-list clearfix">
            <ul>
              <li class="first">
                <div class="node-slide">
                  <img src="http://www.hanselman.com/blog/content/binary/lolcats-funny-pictures-leroy-jenkins.jpg" />
                  <div class="infobox">
                    <h4>Title 1</h4>
                    <p>Teaser 1</p>
                  </div>
                </div>
              </li>
              <li>
                <div class="slide">
                  <img src="http://www.hanselman.com/blog/content/binary/lolcats-funny-pictures-leroy-jenkins.jpg" />
                  <div class="infobox">
                    <h4>Title 2</h4>
                    <p>Teaser 2</p>
                  </div>
                </div>
              </li>
              <li class="last">
                <div class="slide">
                  <img src="http://www.hanselman.com/blog/content/binary/lolcats-funny-pictures-leroy-jenkins.jpg" />
                  <div class="infobox">
                    <h4>Title 3</h4>
                    <p>Teaser 3</p>
                  </div>
                </div>
              </li>
            </ul>
          </div>
        </div>
        <div class="column-2">
          ...
        </div>
        <div class="column-3">
          ...
        </div>
      </body>
    </html>
    

    我发现是

    ul {
      position: relative;
    }
    

    关于导致溢出的ul元素:隐藏不起作用,但为什么,我不知道。此外,还需要使用ul上的left属性来滑动滑块javascript。关于如何解决这个问题的任何想法都是非常受欢迎的。

    2 回复  |  直到 13 年前
        1
  •  182
  •   Niels    15 年前

    这是ie6和ie7中一个众所周知的bug。要解决此问题,需要添加位置:相对于容器。因为在你的例子中,body是容器,我建议你在body的正下方添加一个div并给出它的位置:relative。它应该能解决你的问题。

        2
  •  25
  •   googletorp    15 年前

    这个问题显然是 a known bug 对于IE6+7,在IE8中已修复。

    为了避免这种情况,在这种情况下,您可以替换:

    ul {
        left: -499px;
        position: relative;
      }
    

    用:

    ul {
        margin-left: -499px;
      }
    

    不过,这给了我在infobox div上使用的背景带来了一些问题,但没有什么是我用一些风格的技巧无法解决的。