css margin:auto 在 webkit 浏览器(Chrome 和 Safari)中最大化/全屏时不将 div 居中
我一直无法确定这个问题的原因,所以无法显示测试用例, 相反,我将代码范围缩小到仍然包含错误的页面,而没有太多额外的内容。
这是链接:
http://www.richard-walsh.limewebs.com/Disk-Edits /index.html
问题在于内容 div (id=content) 在 Chrome 和 Safari 中未居中。
它位于右侧。
内容div被一个名为bottom的div包围,其宽度:100%;和高度:自动;。
#bottom{
width:100%;
height:auto;
padding:0px;
margin:0px;
}
#content{
width:862.4px;
height:402px;
margin:auto;
padding-left:10px;
padding-right:10px;
padding-top:5px;
padding-bottom:5px;
background-color:#030303;
background-image:url(images/main.png);
-moz-border-radius:15px;
border-radius:15px;
border-style:solid;
border-color:#181818;
border-width:4px;
margin-top:60px;
-moz-box-shadow: 1px 1px 20px 4px black;
-webkit-box-shadow: 1px 1px 20px 4px black;
box-shadow: 1px 1px 20px 4px black;
overflow:hidden;
}
我发现如果我从内容 css 中删除overflow:hidden,那么它就会正确居中。 但我需要这个(对于链接中未显示的部分)
我还发现,如果我完全删除菜单,它就可以工作。 所以我认为菜单CSS中一定有什么东西导致了这种情况。 它在 Firefox(4) 中运行良好。
我运行的是 Chrome 11.0.696.68 还有Safari 5.0.5
哦!我刚刚注意到,这种情况仅在 Chrome 最大化时发生,当它处于“窗口模式”(由于缺乏更好的名称)时,它会完美居中,即使窗口被拉伸到屏幕的完整尺寸。
我还注意到,如果删除 #copyright,则 #content 会呈现在左侧,如果同时删除 #copyright 和 #choice,则内容 div 会呈现在中心,如果仅删除 #choice,它仍会呈现在右边的。
如果删除#menu_all,则它会正确居中。
任何帮助将不胜感激,
谢谢
I have been unable to determine the cause of this problem, so I can not display a test case,
instead I have narrowed down my code to a page that still contains the fault without too much extra.
Here is the link:
http://www.richard-walsh.limewebs.com/Disk-Edits/index.html
The problem is that the content div (id=content), is not centering in Chrome and Safari.
It is positioned to the right.
The content div is surrounded by a div called bottom, whose width:100%; and height:auto;.
#bottom{
width:100%;
height:auto;
padding:0px;
margin:0px;
}
#content{
width:862.4px;
height:402px;
margin:auto;
padding-left:10px;
padding-right:10px;
padding-top:5px;
padding-bottom:5px;
background-color:#030303;
background-image:url(images/main.png);
-moz-border-radius:15px;
border-radius:15px;
border-style:solid;
border-color:#181818;
border-width:4px;
margin-top:60px;
-moz-box-shadow: 1px 1px 20px 4px black;
-webkit-box-shadow: 1px 1px 20px 4px black;
box-shadow: 1px 1px 20px 4px black;
overflow:hidden;
}
I have found that if I remove overflow:hidden from the content css then it centers correctly.
But I need this (for parts not shown in the link)
I have also found that it works if I remove the menu entirely.
So I think that there must be something in the menu css that has caused this.
It works fine in Firefox(4).
I'm running Chrome 11.0.696.68
and Safari 5.0.5
Oh! I have just noticed that this only happens when Chrome is maximised, when it is in 'window mode' (for lack of a better name) it centers perfectly, even if the window is stretched to the full size of the screen.
I have also noticed that if you remove #copyright, then #content is rendered on the left, and if both #copyright and #choice is removed then the content div renders in the centre, and if you only remove #choice it still renders on the right.
If you remove #menu_all then it centers correctly.
Any help would be much appreciated,
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
添加 display: 块,看看是否有效。
Add display: block, see if that works.
解决办法:
内容 div 上方的 div (#copyright) 没有声明高度值。
声明高度值(35px)解决了我在 chrome/safari 中遇到的问题。
高度:自动;没有用。
这并不能解释为什么当内容 div 直接放置在版权 div 下方时它会起作用。
但仍然。
这是一个可行的解决方案。
因此,如果您遇到类似的问题,请检查上面的 div 是否声明了高度。
The solution:
The div above the content div (#copyright) did not have a height value declared.
Declaring a height value (of 35px) fixed the problem I was having in chrome/safari.
height:auto; did not work.
This does not explain why when the content div was placed directly below the copyright div it worked.
But still.
It was a workable solution.
So if you're have a similar problem then check that the div above has a height declared.
不在#middle 中,而是在#bottom 中。
如果将其向上移动,布局似乎可以正常工作。
Is not in #middle, it's in #bottom.
If you move this up the layout appears to work correctly.