0
我已经制定了一个网页,如下所示窗口的底部之间的格...中心内部的div并使用jQuery
|----------------------|
| |----------| |
| | Logo div | |
| |----------| |
| |
| |----------| |
| | | |
| | Content | |
| | | |
| |----------| |
|----------------------|
目前我正在尝试我div
(Content
)使用居中以下功能:
jQuery.fn.center = function() {
this.css("position","absolute");
this.css("top", (($(window).height() - this.outerHeight())/2) +
$(window).scrollTop() + "px");
this.css("left", (($(window).width() - this.outerWidth())/2) +
$(window).scrollLeft() + "px");
return this;
}
这是我从另一个SO问题得到:Using jQuery to center a DIV on the screen
如果我的分辨率足够大,此功能可以正常工作,但是在较小的屏幕上,它会导致div
我正在以“上来”为中心并与包含上面的徽标的div
共享空间。所以我想用jQuery实现的是将其垂直居中在徽标div
#logo
和页面的“结尾”之间,而不是浮动在标志div
的顶部。
我该如何使用jQuery来做到这一点?