开发者

How do vertically center a div?

开发者 https://www.devze.com 2023-01-29 10:18 出处:网络
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.

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

精彩评论

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