开发者

How do vertically center a div?

I would like to vertically center my main content div. I开发者_StackOverflow社区 am open to using jQuery and/or CSS, but I'd prefer avoiding an extra wrapper div tag.

What do I need to do to do?


jQuery:

$(document).ready(function() {
    $('#main').css('position', 'relative');
    $('#main').css('top', (($('#main').parent().height() - $('#main').height()) / 2) + "px");
});


This question is basically the same as this one, which recommends the following article.

http://www.jakpsatweb.cz/css/css-vertical-center-solution.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜