gpt4 book ai didi

jquery - CSS 或 jQuery 使内容在缩小时垂直居中

转载 作者:行者123 更新时间:2023-11-28 18:15:37 25 4
gpt4 key购买 nike

我无法弄清楚如何在用户缩小时将内容垂直居中。 enter image description here

我有 3 个 div,当它们被缩小时,它们会粘在顶部而不是保持居中,如下所示:enter image description here

蓝色只是第二个 div 的背景。我需要它们垂直居中,而不是在用户缩小时停留在顶部。 (Cntrl/cmd -)

最佳答案

使用 $(window).height() 获取视口(viewport)的高度。使用类似的东西:

$(window).resize(function(){
var ht = $(window).height()/2-$('#theGroupContainer').height()/2+'px';
$('#theGroupContainer').css({top: ht});
})

确保:

body{
position:relative;
}
#theGroupContainer{
position:absolute;
}

% 用于 #theGroupContainer 子级 heightwidth

关于jquery - CSS 或 jQuery 使内容在缩小时垂直居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17958969/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com