如何在没有水平滚动条的情况下将 div(或背景)扩展到水平页面边界之外?
我正在尝试设置一个页面,以便导航栏的背景水平延伸超过窗口边缘,但页面的实际内容保留在 960px 宽的容器内。
这是我到目前为止所得到的链接,它看起来像我想要的那样,但有一个问题。
问题是页面仍然会水平滚动到右侧过度扩展的 div 的末尾。它没有向左的问题,只有向右的问题(我认为这是由于元素处理负边距/定位的方式造成的)。我想我也许可以摆脱:
body {
width: 100%;
overflow-x: hidden;
}
它隐藏了底部滚动条,但您仍然可以使用箭头键向右滚动,如果您将页面大小调整为小于实际内容的 960px,则不会得到像你应该的那样水平滚动条。
有什么方法可以让页面忽略那个 div 的宽度吗?
我 99.9% 确定我在某处看到过这个工作,但我不记得在哪里,并且对负边距/定位的上/左、下/右规则的研究使我相信这可能行不通。有什么想法吗?
另外:我知道我可以使用重复的背景图像来做到这一点,但我试图避免使用图像。
I'm trying to set up a page so that the navigation bar has a background that extends horizontally past the edges of the window, but the actual content of the page remains within a 960px wide container.
Here's a link to what I've got so far, it looks the way I want it to but there's a problem.
The problem is that the page will still scroll horizontally to the end of the over extended div, on the right side. It DOESN'T have this problem going left, only right (which I assume is due to the way elements deal with negative margins/positioning). I thought I might be able to just get away with:
body {
width: 100%;
overflow-x: hidden;
}
Which hides the bottom scroll bar, but you can still scroll right with the arrow key, and if you resize the page smaller than the 960px of actual content, you don't get a horizontal scrollbar like you should.
Is there any way I can make the page ignore the width of just that one div?
I'm 99.9% sure I saw this work somewhere, but I can't remember where, and research on the top/left, bottom/right rules of negative margin/positioning leads me to believe this just might not work. Any ideas?
Also: I know I could probably do this with a repeating background image, but I'm trying to avoid using images.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
position:absolute
&像这样写:检查这个 http://jsfiddle.net/sandeep/pFDDV/5/
You can use
position:absolute
& write like this:check this http://jsfiddle.net/sandeep/pFDDV/5/
你是否也这样期待
http://jsfiddle.net/pFDDV/6/
Are you expecting like this
http://jsfiddle.net/pFDDV/6/