【问题标题】:Position:fixed to work on IE 6/7/8 and mozilla位置:固定在 IE 6/7/8 和 Mozilla 上工作
【发布时间】:2010-09-14 18:44:57
【问题描述】:

我想将 div 的位置固定在页面的右下角..(聊天框)..我如何通过适用于所有 IE6/7/8 和 mozilla 的 css 文件来做到这一点.. ..现在我有

#聊天框{ 位置:固定; 底部:0%; 对:1%;} 这在 IE 上不起作用。我的限制是我只能编辑这个 CSS 文件(所以也不能将 html 设置为严格模式)。我在网上找到的解决方法只是谈论位置 w.r.t 到页面顶部而不是底部。

谢谢 磨难

【问题讨论】:

    标签: css internet-explorer position fixed


    【解决方案1】:

    您可以使用 CSS 表达式修复 IE。使用conditional comments 将以下内容提供给 IE:

    /* smooths out the IE expression scroll - foo doesn't need to exist */
    body{
       background:url(foo) fixed;
    }
    
    /* fixed scrolling element */
    #bottom-fixed-element {
       position: absolute;  
       right: 0;
       top: expression(
          document.body.scrollTop + document.body.clientHeight - this.clientHeight
       );
    }
    

    如果您无法更改源以包含条件注释,您可以使用 CSS hack 解决它,但不建议这样做:

    #bottom-fixed-element {
       position: fixed;
       bottom: 0;
       right: 0;
    
       _position: absolute;  
       _top: expression(
          document.body.scrollTop + document.body.clientHeight - this.clientHeight
       );
    }
    

    编辑

    如果需要同时支持quirks和standards模式,可以在表达式中测试:

    top: expression(
       (document.compatMode && document.compatMode == 'CSS1Compat') ?          
           (documentElement.scrollTop + documentElement.clientHeight - this.clientHeight) :
           (document.body.scrollTop + document.body.clientHeight - this.clientHeight)
    );
    

    【讨论】:

    • 感谢 pat 的回答......它工作得很好......你能解释一下 clientHeight 和 scrollTo 以及 this.clientHeight 属性的含义......我试过谷歌搜索但没有得到一个召集人的答案......抱歉懒惰......谢谢Mohan
    • 当然,document.body.scrollTop 是窗口的当前滚动位置。 document.body.clientHeight 是窗口的当前高度。 this.clientHeight#bottom-fixed-element 的当前高度。
    • 嘿 pat ...上述方案适用于简单的 div,但适用于复杂的 div,例如其中可能包含多个元素的那些 ...不起作用..我的网站 URL 是 aagmgyd6.yahoo.joyent.us/chat/index.html 。 ...这里右下角的聊天框没有固定在它的位置上...在 IE 上 ..如果可能的话,你能看看它..(我知道它要求太多了,但我被困了很多时间最后几周在这里)。
    • 这是因为您的页面未处于怪癖模式。要使其在标准模式下工作,请将表达式更改为:top: expression( documentElement.scrollTop + documentElement.clientHeight - this.clientHeight);
    • 没有办法......让它以页面可能的任何方式工作......我的意思是如果我必须让它适用于所有模式和 IE6/7 /8..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多