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

Internet Explorer中的绝对定位和滚动条

  •  3
  • LandonSchropp  · 技术社区  · 14 年前

    免责声明

    here . 虽然有一个人很好心地帮助我,但他最终还是找不到理想的解决办法。实际情况是Doctype并不像Stack Overflow那样拥有大量的用户。这对我来说是个重要的问题,我真的需要更多的意见。

    问题

    我用HTML和CSS实现了一个树视图。当悬停此树视图中的某个项目时,该项目下会显示工具提示。在Firefox中一切都很好,但在Chrome或Firefox中就不行了。

    我的问题是工具提示使用绝对定位来允许其内容显示在其他元素上。当我在Firefox中滚动时,这些工具提示的位置会移动以反映它们的新位置。但是,Internet Explorer保留了元素的原始位置。因此,如果将鼠标悬停在滚动的元素上,工具提示将显示在该元素最初所在的位置下。

    我已经读到,可以通过添加position:相对于我的树视图来解决这个问题,但是这会阻止工具提示在整个页面上悬停。

    下面是一些示例代码来说明我的问题:

    <!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">
     <head>
      <title>Example</title>
    
      <!-- import css files -->
      <link href="example.css" rel="stylesheet" type="text/css" />
     </head>
     <body>
      <div id="wrapper">
       <div id="tree-view">
        <a href="#">tooltip example
         <span class="tooltip">
          <strong>Info</strong>
          <span class="tooltip-info">
           Here is some information about the thing you're hovering over.
          </span>
         </span>
        </a>
        <a href="#">tooltip example
         <span class="tooltip">
          <strong>Info</strong>
          <span class="tooltip-info">
           Here is some information about the thing you're hovering over.
          </span>
         </span>
        </a>
        <a href="#">tooltip example
         <span class="tooltip">
          <strong>Info</strong>
          <span class="tooltip-info">
           Here is some information about the thing you're hovering over.
          </span>
         </span>
        </a>
        <a href="#">tooltip example
         <span class="tooltip">
          <strong>Info</strong>
          <span class="tooltip-info">
           Here is some information about the thing you're hovering over.
          </span>
         </span>
        </a>
        <a href="#">tooltip example
         <span class="tooltip">
          <strong>Info</strong>
          <span class="tooltip-info">
           Here is some information about the thing you're hovering over.
          </span>
         </span>
        </a>
        <a href="#">tooltip example
         <span class="tooltip">
          <strong>Info</strong>
          <span class="tooltip-info">
           Here is some information about the thing you're hovering over.
          </span>
         </span>
        </a>
        <a href="#">tooltip example
         <span class="tooltip">
          <strong>Info</strong>
          <span class="tooltip-info">
           Here is some information about the thing you're hovering over.
          </span>
         </span>
        </a>
        <a href="#">tooltip example
         <span class="tooltip">
          <strong>Info</strong>
          <span class="tooltip-info">
           Here is some information about the thing you're hovering over.
          </span>
         </span>
        </a>
        <a href="#">tooltip example
         <span class="tooltip">
          <strong>Info</strong>
          <span class="tooltip-info">
           Here is some information about the thing you're hovering over.
          </span>
         </span>
        </a>
        <a href="#">tooltip example
         <span class="tooltip">
          <strong>Info</strong>
          <span class="tooltip-info">
           Here is some information about the thing you're hovering over.
          </span>
         </span>
        </a>
        <a href="#">tooltip example
         <span class="tooltip">
          <strong>Info</strong>
          <span class="tooltip-info">
           Here is some information about the thing you're hovering over.
          </span>
         </span>
        </a>
        <a href="#">tooltip example
         <span class="tooltip">
          <strong>Info</strong>
          <span class="tooltip-info">
           Here is some information about the thing you're hovering over.
          </span>
         </span>
        </a>
        <a href="#">tooltip example
         <span class="tooltip">
          <strong>Info</strong>
          <span class="tooltip-info">
           Here is some information about the thing you're hovering over.
          </span>
         </span>
        </a>
        <a href="#">tooltip example
         <span class="tooltip">
          <strong>Info</strong>
          <span class="tooltip-info">
           Here is some information about the thing you're hovering over.
          </span>
         </span>
        </a>
        <a href="#">tooltip example
         <span class="tooltip">
          <strong>Info</strong>
          <span class="tooltip-info">
           Here is some information about the thing you're hovering over.
          </span>
         </span>
        </a>
        <a href="#">tooltip example
         <span class="tooltip">
          <strong>Info</strong>
          <span class="tooltip-info">
           Here is some information about the thing you're hovering over.
          </span>
         </span>
        </a>
        <a href="#">tooltip example
         <span class="tooltip">
          <strong>Info</strong>
          <span class="tooltip-info">
           Here is some information about the thing you're hovering over.
          </span>
         </span>
        </a>
        <a href="#">tooltip example
         <span class="tooltip">
          <strong>Info</strong>
          <span class="tooltip-info">
           Here is some information about the thing you're hovering over.
          </span>
         </span>
        </a>
        <a href="#">tooltip example
         <span class="tooltip">
          <strong>Info</strong>
          <span class="tooltip-info">
           Here is some information about the thing you're hovering over.
          </span>
         </span>
        </a>
        <a href="#">tooltip example
         <span class="tooltip">
          <strong>Info</strong>
          <span class="tooltip-info">
           Here is some information about the thing you're hovering over.
          </span>
         </span>
        </a>
        <a href="#">tooltip example
         <span class="tooltip">
          <strong>Info</strong>
          <span class="tooltip-info">
           Here is some information about the thing you're hovering over.
          </span>
         </span>
        </a>
        <a href="#">tooltip example
         <span class="tooltip">
          <strong>Info</strong>
          <span class="tooltip-info">
           Here is some information about the thing you're hovering over.
          </span>
         </span>
        </a>
        <a href="#">tooltip example
         <span class="tooltip">
          <strong>Info</strong>
          <span class="tooltip-info">
           Here is some information about the thing you're hovering over.
          </span>
         </span>
        </a>
        <a href="#">tooltip example
         <span class="tooltip">
          <strong>Info</strong>
          <span class="tooltip-info">
           Here is some information about the thing you're hovering over.
          </span>
         </span>
        </a>
       </div>
       <div id="main-content">
        main
       </div>
      </div>
     </body>
    </html>
    

    #wrapper
    {
    }
    
    #tree-view
    {
     float: left;
     width: 200px;
     height: 400px;
     background-color: #BBFFFF;
     overflow: auto;
    }
    
    #main-content
    {
     float: left;
     width: 600px;
     height: 400px;
     background-color: #FFFFBB;
    }
    
    #tree-view a
    {
     display: block;
     position: relative;
    }
    
    #tree-view a span.tooltip
    {
     position: absolute;
     z-index: 100;
     display: none;
    }
    
    #tree-view a:hover span.tooltip
    {
     /* positioning */
     margin-left: 1em;
     margin-top: 1em;
     display: block;
     position: absolute;
    
     /*formatting*/
     text-decoration: none;
     background: #DDD;
     border: 1px solid #BBB;
     padding: 5px;
     white-space: normal;
     width: 300px;
     color: black;
    }
    
    #tree-view .tooltip strong
    {
     display: block;
    }
    
    #tree-view .tooltip .tooltip-info
    {
     display: block;
    }
    

    如果position:relative标记从工具提示锚中移除,那么工具提示将在Firefox中正确显示。但是,如果没有它,工具提示将无法在Internet Explorer中正确显示。

    2 回复  |  直到 14 年前
        1
  •  2
  •   bpeterson76    14 年前

    我停止使用自己的工具提示,转而使用Qtip( http://craigsworks.com/projects/qtip/

    在即将发布的jqueryui中,内核中也将内置类似的功能。类似的脚本可用于Dojo、Prototype和MooTools。

        2
  •  1
  •   michael    14 年前

    工具提示不会出现在IE6中,奇怪的是,你可以通过给锚定的悬停状态一个背景色来解决这个问题。。。

    #tree-view a
    {
     background-color:#ff0000;
    }
    

    我想它只需要有布局,但通常zoom:1; 或者position:relative; 没有同样的效果

    你可以通过使用。。。

    #tree-view
    {
     overflow: display;
    }