日期:2014-05-17  浏览次数:20611 次

如何让一个table始终上下居中,不随滚动条而动
RT,就像许多页面中"回到顶部"那个玩意一样,不管页面多长,它的位置都不动.
------解决方案--------------------
使用CSS 的 position:fixed;
.reTop{
width:100px; 
height:100px; 
position:fixed; 
top:50%; 
right:20px; 
margin:-50px 0
}
------解决方案--------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>div固定位置</title>

<style type="text/css">
*{
margin: 0px;
padding: 0px;
}
body{height:2000px;}
#topNav {
position: fixed;
background-color:#fff;
color:#f6f6f6;   
border: 1px solid #1C5FBB;
_border: 1px solid #1C5FBB;
text-align: center;   
line-height: 20px;   
font-size: 13px; 
z-index:999;   
width: 500px;   
height: 200px;   
left:50%;   
top:50%;   
margin-left:-220px!important;/*FF IE7 该值为本身宽的一半 */
margin-top:-100px!important;/*FF IE7 该值为本身高的一半*/
margin-top:0px;   
position:fixed!important;/* FF IE7*/
position:absolute;/*IE6*/
_top:       expression(eval(document.compatMode &&   
            document.compatMode=='CSS1Compat') ?   
            documentElement.scrollTop + (document.documentElement.clientHeight-this.offsetHeight)/2:/*IE6*/
            document.body.scrollTop + (document.body.clientHeight - this.clientHeight)/2);/*IE5 IE5.5*/
border:1px solid #ccc;
}
</style>
</head>

<body>
<div id="topNav">
    <div class="right">
        <table cellpadding="0" cellspacing="0">
            <tr>
                <td><a href="#">简体中文</a></td>
                <td>
------解决方案--------------------
</td>
                <td><a href="#">繁体中文</a></td>
                <td>
------解决方案--------------------
</td>
                <td><a href="#">收藏本站</a></td>
            </tr>
        </table>
    </div>
</div>
</body>
</html>