中心站点位于屏幕中央
我正在开发一个网站,希望将该网站集中在屏幕中央(水平和垂直),但不能。 我只能将其水平居中。
由于我一直在搜索并尝试将它们应用到我的网站时找到的解决方案,所以一切都被破坏了。
I am developing a site and want to centralize this site in the center of the screen (horizontally and vertically) but can not.
I could only centers it horizontally.
Since I've been searching and the solutions I found when I try to apply them to my site, it all mangled.
This is the website http://amsdarquitetura.com.br/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这就是您所需要的:
将其放在您的父 div 上。
This is what you need:
Put this on your parent div.
为了引导您走上正确的道路,请尝试使用 JAVASCRIPT(可能需要添加标签)来检测 window.height。
然后减去主 div 的高度。
然后除以 2(顶部/底部)
最后,向主 div 添加“margin-top”。
To lead you down the right path, try using JAVASCRIPT (might want to add a tag) to detect the window.height.
Then subtract the height of your main div.
Then divide by 2 (top/bottom)
And finally, add a 'margin-top' to the main div.
水平很容易:
垂直则困难得多,并且可能需要 CSS3 或 javascript 定位。
Horizontal is easy:
Vertical is much more difficult, and will likely require CSS3 or javascript positioning.
您必须为整个网站定义高度和宽度,以使其在两个方向上保持居中。
从那里开始,它只是对垂直居中进行数学计算。水平是非常自动的,定义宽度并具有 margin:0 auto; (不要使用 5px 自动。)。
这是一篇关于垂直居中的不错的文章:
http://blog.themeforest.net/教程/垂直居中-with-css/
You'll have to define a height and width for your whole site to keep it centered in both directions.
From there, it's just doing the math on your vertical centering. Horizontal is pretty automatic with defining a width and having the margin:0 auto; (Don't use 5px auto.).
Here's a decent article on vertical centering:
http://blog.themeforest.net/tutorials/vertical-centering-with-css/
有一个 jQuery 插件可以做到这一点。我看到您已经在主页上使用了 jQuery。
http://www.seodenver.com/simple-vertical-align- 正如您所发现的,
用于执行此操作的 CSS 选项似乎很复杂、不可靠且很糟糕。
您可以实现自定义 jQuery 函数来完成相同的操作。但是,当其他人已经解决了问题时,为什么还要维护该代码呢?
There is a jQuery plugin to do this. I see you already using jQuery on your main page.
http://www.seodenver.com/simple-vertical-align-plugin-for-jquery/
It seems the CSS options for doing this are complicated, unreliable, and hacky, as you found out.
You could implement a custom jQuery function to do the same thing. But why maintain that code when someone else has the problem solved already?