解决方法
在MicroTut中有一篇很棒的文章来做
http://tutorialzine.com/2010/03/centering-div-vertically-and-horizontally/
以CSS为中心:
- .className{
- width:300px;
- height:200px;
- position:absolute;
- left:50%;
- top:50%;
- margin:-100px 0 0 -150px;
- }
以JQuery为中心:
- $(window).resize(function(){
- $('.className').css({
- position:'absolute',left: ($(window).width() - $('.className').outerWidth())/2,top: ($(window).height() - $('.className').outerHeight())/2
- });
- });
- // To initially run the function:
- $(window).resize();
你可以看到一个演示here