Div 固定

让Div固定在屏幕的正上方,或任意位置。兼容IE6(有一点抖动)、IE7、IE5、火狐、谷歌、Opera、Safari未测试。

代码如下:

<span id="spMessage" style="background-color: #016011; color: White; z-index: 9999;position: fixed; font-size: 13px; font-family: 微软雅黑; padding: 3px 10px; display: none; 

height:20px;top:18px;left:10px;_position:absolute;_top: expression(documentElement.scrollTop + this.offsetHeight + 18);">欢迎光临</span>

或者下面的代码,支持高版本 IE7+ 或其它浏览器

<div style="position:absolute;position:fixed !important; top:0px; left:0px;line-height:24px; color:white; text-align:center; cursor:pointer;background:#000;z-index:10000;100%; font-weight:bold;" onmouseover="this.style.color='red';" onmouseout="this.style.color='white';">
这里是内容
</div>

谢谢浏览!

原文地址:https://www.cnblogs.com/Music/p/DivFixed.html