垂直放置页面内容 [英] Centering page content vertically

查看:121
本文介绍了垂直放置页面内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何使用CSS水平居中整个页面。但是有没有办法垂直中心的页面?这样的东西...

I know how I can horizontally center the entire page with CSS. But is there a way to vertically center the page? Something like this...

推荐答案

MicroTut要做到这一点 http://tutorialzine.com/2010/03/centering-div-vertical和水平/

There's a great article in MicroTut to do that 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为中心:

Centering with 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();

您可以看到一个演示这里

这篇关于垂直放置页面内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆