浏览器上的水平滚动条表明我的网站右侧有空白,是什么原因造成的?
我开发这个网站已经有一段时间了,今天突然我注意到浏览器上的水平滚动条正在显示,并且允许网站向右滚动一两英寸。
整个网站只有 960 像素宽,而我的屏幕分辨率是 1680 像素,所以显然它应该适合足够的空间。
该网站仍然显示完全相同,但滚动条让我很恼火。我尝试过使用 CSS 中的 *
选择器为所有内容添加边框,但似乎没有任何东西突出那额外的英寸。我还使用 Google Chrome 控制台突出显示网站的不同部分,但它们都没有导致问题。
每个浏览器都显示同样的问题,你有什么解释吗?
这是有问题的网站:http://compressmycode.com/
I've been developing this site for a while and suddenly today I noticed that the horizontal scrollbar on my browser was showing and was allowing the site to be scrolled an inch or two to the right.
The whole site is only 960px wide and my screen resolution is 1680px so clearly it should fit with plenty of space.
The site still displays exactly the same but the scrollbar is annoying me. I've tried adding borders to everything using the *
selector in CSS but nothing seems to be protruding that extra inch. I've also used the Google Chrome console to highlight different sections of the site but none of them are causing the problem.
Every browser shows the same problem, do you have any explanations?
This is the site in question: http://compressmycode.com/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
删除 CSS 第 31 行周围的
#body-wrapper
样式中的position:relative
并使用margin-top:50px
而不是top:50px
如果您必须保留
position:relative
您也可以将overflow:hidden
应用于您的包装器以删除可能存在的任何溢出,但也有一些这样做存在固有的危险。编辑
经过进一步检查,我发现您的
.right
div 是问题所在。由于某种原因,它向右浮动会导致您出现问题。remove the
position:relative
in your#body-wrapper
style around line 31 of your CSS and usemargin-top:50px
instead oftop:50px
if you must keep the
position:relative
you can also just apply anoverflow:hidden
to your wrapper to remove whatever overflow may be there, but there are some inherent dangers in doing so.EDIT
Upon further inspection, I've discovered that your
.right
div is the issue. For some reason, its being floated to the right is causing your problems.问题出在你的 JS 上。如果禁用它,它会完美运行。
更准确地说,使用 Facebook 按钮:
div#body-wrapper > div#site-title >右分区> div.fb-root > div
将其设置为溢出:隐藏,修复了问题
The problem comes form your JS. if you disable it, it works perfectly.
More precisely with the facebook button:
div#body-wrapper > div#site-title > div.right > div.fb-root > div
setting this to overflow: hidden, fixes the problem
我有类似的问题。似乎没有什么超出宽度的东西,但底部仍然有一个滚动条。
我的页面结构是:
*sharethis:http://www. sharethis.com/#sthash.r7Bx1kDr.dpbs
我不会共享 CSS,因为除了外部级别和顶部边缘的框阴影之外没有其他任何东西。
虽然我会分享问题是如何解决的。
我给了
css:
这解决了我的滚动问题。
尽管修复只是找到正确的父级并为其提供上面的 CSS,但
我仍然想知道滚动的根本原因。如果您有这些知识,请分享。
I had a similar issue. There was nothing that seemed to exceed the width but still there was a scroll bar at the bottom.
My structure of page was:
*sharethis: http://www.sharethis.com/#sthash.r7Bx1kDr.dpbs
I'm not sharing the CSS as there was nothing other than box-shadows at the outer levels and top-margin.
Although i'll share how the problem got fixed.
I gave the
css:
This fixed the scroll issue for me.
Although the fix was just to find the right parent and give it the above
CSS
I still would like to know the root cause for the scroll. Kindly share that knowledge if you have it.