CSS implementation of fixed elements in the lower right corner of the page floating layer effect (compatible with IE, chrome, Firefox)

Source: Internet
Author: User

But under the IE6, the position:fixed attribute is not supported, and we need to handle the IE6 hack. The solution is to use the Postion:absolute attribute, its role is very familiar, relative to the parent element for absolute positioning, and then we can through expression to change the #ads top value.


The definition of PS expression: IE5 and later versions support the use of expression in CSS to associate CSS properties with Javas cript expressions, where CSS properties can be intrinsic attributes of elements or custom attributes. This means that the CSS property can be followed by a javas cript expression, and the value of the CSS property equals the result of the Javas cript expression calculation. You can refer directly to the properties and methods of an element itself in an expression, or you can use a different browser object. This expression is as if it were in a member function of this element.

So we can change the top value by calculating the JavaScript value in the CSS, the code is as follows:

The code is as follows Copy Code

#ads {
_position:absolute;
_top:expression (Documentelement.scrolltop + documentelement.clientheight-this.offsetheight);
}

It seems like everything is perfect, but when we run under IE6 we find that as the scroll bar moves, our #ads friend shakes. The solution is also very simple, as long as the body Riga a little bit of CSS, as follows:

The code is as follows Copy Code

body{
Background-image:url (About:blank); /* for IE6 * *
background-attachment:fixed; /* MUST * *
}

Example

The code is as follows Copy Code
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title>demo</title>
<style>
#top {
BORDER:1PX solid blue;
Background: #ccc;
width:200px;
height:150px;
position:fixed;
_position:absolute;
bottom:0;
right:0;
_top:expression (eval (document.documentelement.scrolltop+ document.documentelement.clientheight-this.offsetheight-(parseint (this.currentstyle.margintop,10) | | 0)-(parseint (this.currentstyle.marginbottom,10) | | 0));
}

*html{
Background-image:url (About:blank);
background-attachment:fixed;
}
</style>
<body >
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/>< br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/><br/><br/><br/><br/>

<div id= "Top" >
Test effect
</div>
</body>

In fact, now we can not consider the IE6 after all, IE6 has expired oh.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.