css实现:
<style type="text/css">
.middle{
width:300px;
height:200px;
position:absolute;
left:50%;
top:50%;
margin:-100px 0 0 -150px ;
border:1px solid red;
}
</style>
</head>
<body>
<div class="middle"></div>
</body>
</html>
js实现:
<style type="text/css">
.middle{
width:300px;
height:200px;
border:1px solid red;
}
</style>
</head>
<body>
<div class="middle"></div>
</body>
<script type="text/javascript">
$(function(){
$(".middle").css({
position:"absolute",
left:($(window).width()-$(".middle").width())/2,
top:($(window).height()-$(".middle").height())/2,
})
})
</script>
</html>
原文地址:http://warmdoll.blog.51cto.com/10881334/1761201