css代码

<style type=”text/css”>
#center{ width:700px; height:100px; background-color:#333; margin:0px auto;}
</style>

html代码

<div id=”center”>
</div>

JS代码

<script type=”text/javascript”>
function change(){
var winH=window.innerHeight;
var divH=document.getElementById(“center”).offsetHeight;
var FH=(winH-divH)/2;
document.getElementById(“center”).style.marginTop=FH+’px’;}
window.onload=change;
window.onresize=change;
</script>