方法一
思路:就是你设计的版面有多大;
比如:你设计的版面宽是1004PX的,那么你就把那层宽度设计为1004,上、下为0;左、右为自动
#main {
width: 1004px;
margin-top: 0px;
margin-right: auto;
margin-bottom: 0px;
margin-left: auto;
}
方法二
#top {
position: relative;
height: 109px;
width: 1004px;
margin:0 auto;
}
方法三
<script language="JavaScript">
function scrollbox() {
var box = document.getElementByIdx('box');
box.style.top = document.body.scrollTop + (document.body.clientHeight - box.style.pixelHeight) / 2;
box.style.left = document.body.scrollLeft + (document.body.clientWidth - box.style.pixelWidth) / 2 ;
}
</script>
<body onload="scrollbox()" onscroll="scrollbox()" onresize="scrollbox()">
<div id="box" style="position: absolute; width: 100px; height: 100px; background-color: red;"></div>
<img height="1000" />