使用 Overflow-x:hidden 时 Firefox 中的两个垂直滚动条
我刚刚为客户建立了一个网站,我遇到了一个只出现在 Firefox 浏览器中的奇怪问题。
在页面顶部,我有一个填充浏览器宽度的导航栏。我使用了此处描述的技术 http://css-tricks.com/full-browser-width-bars/< /a> 尽可能在语义上达到效果。然后我必须在 html 和 body 标签上放置overflow-x:hidden,以防止用户滚动到屏幕右侧。
这在我测试过的所有浏览器中都表现良好,包括 Mac/PC 上的 Safari、Opera、Chrome,但即使是 IE7、8 和 IE7、8 也同样如此。 9想玩得好。但哦,不,Firefox 只是不想接受它。
虽然我没有水平滚动条(这是理想的效果),但 Firefox 决定将垂直滚动条的数量增加一倍。如果使用鼠标,我无法水平滚动,但当我在 Mac 上使用触控板时,垂直移动受到限制,这意味着我无法向下滚动页面,如果我用两根手指滑动,页面就会水平滚动到遗忘状态。
我在谷歌和其他地方发现的唯一的事情是这种行为是 Firefox 中的一个错误?
非常感谢任何有关此烦恼的帮助,非常感谢。
更新:添加代码
基本上代码就是这样,因为有太多的内容显示了全部。我会向您指出该网站,但客户还不希望它上线。开始吧:
<nav id="menu">
<ul>
<li>Menu Item 1</li>
<li>Menu Item 2</li>
<li>Menu Item 3</li>
</ul>
</nav>
那么全角浏览器栏的 css 就是这样的,如上面的链接所示:
html,body{
overflow-x: hidden; /*This prevents the user from scrolling horizontally*/
}
#menu{
position: relative;
background: blue;
}
#menu:before, #menu:after{
content:'';
position: absolute;
background: inherit;
top: 0;
bottom: 0;
width: 9999px; /*huge width to ensure bar fills browser*/
}
#menu:before{
right: 100%;
}
#menu:after{
left: 100%;
}
Ive just built a website for a client, and Ive got an odd problem that only occurs in Firefox browser.
At the top of the page I have a navigation bar that fills the width of the browser. Ive used the technique described here http://css-tricks.com/full-browser-width-bars/ to achieve the effect as semantically as possible. Then Ive had to place overflow-x:hidden on the html and body tags to prevent the user from being able to scroll off the right side of the screen.
This works great in every browser I've tested it in from Safari on Mac/PC, Opera, Chrome and heaven forbid, but even IE7, 8 & 9 wanted to play nice. But oh no Firefox just doesn't want to go along with it.
Although Ive no horizontal scroll bars which is the desired effect, Firefox has decided to double up on the amount of vertical scrollbars. I can't scroll horizontally if using a mouse, but when I use the trackpad on the Mac, the vertical movement is restricted, meaning I cant scroll down the page and if I do a two finger swipe the page scrolls off horizontally into oblivion.
The only thing I have found on google and elsewhere is that this behaviour is a bug in Firefox?
Any help with this annoyance is greatly appreciated, Many Thanks.
Update: Added Code
Basically the code is this as theres too much show it all. I would point you to the site but the client doesn't want it live yet. Here we go:
<nav id="menu">
<ul>
<li>Menu Item 1</li>
<li>Menu Item 2</li>
<li>Menu Item 3</li>
</ul>
</nav>
Then the css is this for a fullwidth browser bar as the link above:
html,body{
overflow-x: hidden; /*This prevents the user from scrolling horizontally*/
}
#menu{
position: relative;
background: blue;
}
#menu:before, #menu:after{
content:'';
position: absolute;
background: inherit;
top: 0;
bottom: 0;
width: 9999px; /*huge width to ensure bar fills browser*/
}
#menu:before{
right: 100%;
}
#menu:after{
left: 100%;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
刚刚出现了类似的问题;我的解决方案是简单地添加:
这样就解决了问题。只是想将其发布在这里,因为它不断出现在搜索结果中。
Just had a similar issue come up; my solution was to simply add:
And that solved it. Just wanted to post it here 'cause this kept popping up in the search results.
好的,我已经解决了。与我更好的判断相反,我只是从网络上的任何旧网站复制并粘贴了一个clearfix hack。经过几个小时的故障排除后,我发现这一切都归咎于clearfix,全角条没有按预期工作。我将其范围缩小到clearfix hack的css内容标签。由于某种原因,它有一个“.”。作为内容插入。我删除了它,然后添加
到clearfix css 块的末尾,它就工作了。 Firefox 中不再有水平滚动条,也不再有 x2 垂直滚动条。
OK, I sorted it out. Against my better judgement, I just copied and pasted a clearfix hack from any old site on the net. After many hours troubleshooting, Ive found that it was all down to clearfix that the fullwidth bars weren't working as expected. I narrowed it down to the css content tag of the clearfix hack. For some reason it had had a '.' inserted as the content. I removed this and then added
onto the end of the clearfix css block and it worked. No more horizontal scrolling, no more x2 vertical scrollbars in Firefox.
对我来说解决这个问题的方法是将滚动条代码移至仅 html 而不是“body,html”。我想它可能会制作两个滚动条,因为它同时放入了 html 和 body 中。尽管这引入了一些其他问题。我想我会用一个额外的 div 来代替。
What fixed it for me was moving over the scrollbar code to html only instead of "body, html". I figured maybe it's making two scrollbars because its put in both html and body. Though this introduced some other problems. Think I'll go with an additional div instead.