[原创]使用CSS将Div固定在窗口的右下角

发布时间:2012年02月10日      浏览次数:1038 次
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>使用CSS将Div固定在窗口的右下角</title>
<style>
#INDEXT_RB_AD{
clear:both; width:200px; height:100px; z-index:1000; overflow:hidden; border:1px #ccc solid;
bottom:5px; right:5px;

/* 火狐、Google浏览器只需要后面这一句代码即可 */
position:fixed !important;

/* 以下代码是针对IE6的 */
_position:absolute;
_top: expression( eval( document.documentElement.scrollTop + document.documentElement.clientHeight - this.offsetHeight - (parseInt(this.currentStyle.marginTop,10)||0) - (parseInt(this.currentStyle.marginBottom,10)||0) ) - (parseInt(this.currentStyle.bottom,10)||0) );
}
</style>
</head>
<body>
<div style="height:2000px;">使用CSS将Div固定在窗口的右下角</div>
<div id="INDEXT_RB_AD" style="display:;">
<div align="right" style=" width:100%; height:25px; line-height:25px; cursor:pointer; " onclick="document.getElementById('INDEXT_RB_AD').style.display = 'none';">关闭</div>
<div>这里是您要显示的内容</div>
</div>
</body>
</html>

==============================================================================
如果要将该功能写入js文件里,供网站多个页面同时调用,可以使用下列代码
==============================================================================

<script>
//var RB_FLOAT_AD = "no"; //在不需要显示的页面加上此行代码
if ( typeof(RB_FLOAT_AD) == "undefined" || RB_FLOAT_AD != "no" ){
      //输出CSS样式
      document.write('<style>#INDEXT_RB_AD{ clear:both; width:200px; height:100px; z-index:1000; overflow:hidden; border:1px #ccc solid; bottom:10px; right:5px; /* 火狐、Google浏览器只需要后面这一句代码即可 */ position:fixed !important; /* 以下代码是针对IE6的 */ _position:absolute; _top: expression( eval( document.documentElement.scrollTop + document.documentElement.clientHeight - this.offsetHeight - (parseInt(this.currentStyle.marginTop,10)||0) - (parseInt(this.currentStyle.marginBottom,10)||0) ) - (parseInt(this.currentStyle.bottom,10)||0) ); }</style>');
      //
      document.write('<div id="INDEXT_RB_AD" style="display:;"><div align="right" style=" width:100%; height:25px; line-height:25px; cursor:pointer;" onclick="document.getElementById('INDEXT_RB_AD').style.display = 'none';">关闭</div><div>这里是您要显示的内容</div></div>');
}
</script>
文章来源:桂林视窗生活网
免责声明:本站相关技术文章信息部分来自网络,目的主要是传播更多信息,如果您认为本站的某些信息侵犯了您的版权,请与我们联系,我们会即时妥善的处理,谢谢合作!