如何在窗口调整大小时使用jquery水平居中相对div? [英] how to center a relative div horizontally using jquery on window resize?

查看:79
本文介绍了如何在窗口调整大小时使用jquery水平居中相对div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最初使用jquery水平居中div但是当窗口调整大小时它看起来很糟糕所以我想做的是在调整窗口大小后使用jquery使其居中



<有没有办法帮忙?



编辑



我有的人成功地使其他元素居中但我现在有另一个问题:(



请检查这个
http://hrmanagementbradford.com/gallery/



并调整窗口大小,你会看到内容没有正确定位,我试图解决这个问题几个小时但无法找到解决方案请帮助



编辑
解决了!它很复杂,而且我的代码非常具体,所以在这里发布也无济于事:)

虽然我用jquery来居中但是如果我们使用css的东西那么FutureKode的答案是最好的适合我:)

解决方案

为什么你使用jquery水平居中当css可以做到一行时它会在浏览器调整大小时保持在中心位置:

  div {
margin:0 auto;
宽度:800px
}


i am initially centering div horizontally using jquery but when the window is resized it looks bad so what i want to do is keep it centered using jquery after the window is resized

is there a way to help?

EDIT

guys i have successfully made other elements centered but i am having another issue now :(

please check this http://hrmanagementbradford.com/gallery/

and resize the window, you will see that the content doesn't get positioned correctly, i am trying to fix this for hours but can't find the solution please help with that

EDIT solved! it was complex and my code is very specific so posting it here won't help :) and although i used jquery to center it but if we use the css thing then FutureKode's answer is best suited for me :)

解决方案

Why are you using jquery to center horizontally when css can do it one line and it will stay in the center when the browser is resized:

div {
margin:0 auto;
width:800px
}

这篇关于如何在窗口调整大小时使用jquery水平居中相对div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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