views:

36

answers:

1

hello all, I want to make a div's position fixed on the bottom right of a page..( a chat box) ..how do i do that through a css file which will work on all IE6/7/8 and mozilla ....for now i have

#chatBox{ position: fixed; bottom: 0%; right: 1%;} This doesn't work on IE..and my constraint is that I am just allowed to edit this CSS file ( so can't set the html to strict mode too). Workarounds I found on the web just talk about position w.r.t to the top of the page not bottom.

thanks Mohan

A: 

You can fix IE with CSS expressions. Serve the following to IE with conditional comments:

/* 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
   );
}

If you're not able to alter the source to include a conditional comment, you can get around it with CSS hacks, but it's not recommended:

#bottom-fixed-element {
   position: fixed;
   bottom: 0;
   right: 0;

   _position: absolute;  
   _top: expression(
      document.body.scrollTop + document.body.clientHeight - this.clientHeight
   );
}

Edit

If you need to support both quirks and standards mode, you can test in the expression:

top: expression(
   (document.compatMode && document.compatMode == 'CSS1Compat') ?          
       (documentElement.scrollTop + documentElement.clientHeight - this.clientHeight) :
       (document.body.scrollTop + document.body.clientHeight - this.clientHeight)
);
Pat
thanks pat for the answer ..it works perfectly fine....Can you kindly explain me the meaning of the clientHeight and scrollTo and this.clientHeight attributes....i tried googling it but didnt get a convening answer......sorry for being lazy....Thanks Mohan
Sure, `document.body.scrollTop` is the current scroll position of the window. `document.body.clientHeight` is the current height of the window. `this.clientHeight` is the current height of `#bottom-fixed-element`.
Pat
hey pat ...the above scheme works for simple div's but for complicated div's like the ones that may have multiple elements inside them ...is not working ..my sites URL is http://aagmgyd6.yahoo.joyent.us/chat/index.html ....here the chatbox on the bottom right is not getting fixed in its position...on IE ..if possible can you please look at it ..(i know its too much to ask for but i am stuck big time for last few weeks here).
It's because your page isn't in quirks mode. To make it work in standards mode, change the expression to: `top: expression( documentElement.scrollTop + documentElement.clientHeight - this.clientHeight);`
Pat
isn't there a way ...so that it works in whatever way the page might me .....I mean If I have to make it work for all modes and for IE6/7/8..
By the way it still doesn't seem to work ... I am using IE8 to test it ...and using inbuild IE developer tool t try things in quirks mode and IE 7 mode ....but in quirk's mode and IE 7 mode the chat box disappears..and in IE 8 mode it doesn't remain fixed ......by the thanks for all the help you have been .....thanks Mohan
In theory you should only need the expression for IE6 and yes, you can test which mode you're page is in. See my edits.
Pat
which edits do you mean?
oh sorry didn't see ...got your edits ...