首页 > 开发 > CSS > 正文

跨浏览器的CSS固定定位

2024-07-11 08:20:55
字体:
来源:转载
供稿:网友

本文介绍了跨浏览器的css固定定位,请看下面的例子:

<!doctype html public "-//w3c//dtd xhtml 1.0 strict//en"
"http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
……
<style type="text/css">
#fixed{position:fixed;top:5em;right:0;……}   /*针对ie7、opera、firefox一行搞定*/
</style>
/*ie6中利用容器对溢出内容的处理方式来实现的*/
<!–[if ie 6]>
<style type="text/css">
html{overflow:hidden;}
body{height:100%;overflow:auto;}
#fixed{position:absolute;right:17px;}
/*fixed元素的绝对位置是相对于html元素来说,滚动条是body元素的,这是设置right:17px的原因*/
</style>
<![endif]–>
<!–[if lt ie 6]>
<style type="text/css">
#fixed{position:absolute;top:expression(eval(document.body.scrolltop + 50));}
</style>
<![endif]–>
</head>
<body>
<div id="wrapper">
……
</div>
<div id="fixed"><h2>{position:fixed}</h2></div>
</body>
</html>

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表