背景附件滚动与固定
我有一个宽度为 2000px 的背景图像。它是按以下方式准备的:在更高分辨率的显示器中,中心 1000 像素用于内容,左侧和右侧额外 500 像素作为边距。
我希望它以每一个决议为中心。
当我尝试使用 bg {background:url(bg.jpg) no-repeat center topfixed; 进行处理时}
图像正确居中,但显然不滚动。
因此,我将 fixed
替换为 scroll
: bg {background:url(bg.jpg) 无重复中心顶部滚动; }
但图像不居中 - 它从左上角开始显示,因此在较小的分辨率下您可以看到不应该可见的左边距。
以下是 jsfiddle.net 上的示例。使用 background-attachment
值 scroll
/fixed
并尝试减小结果窗口的大小,希望您能理解我的意思。
你能帮我解决这个问题吗?
I have an image for background which is 2000px width. It is prepared in a following way: 1000px in the center for content, and additional 500px on the left and right for margins in higher resolution monitors.
I would like it to be centered on every resolution.
When I try it to do with bg {background:url(bg.jpg) no-repeat center top fixed; }
image is properly centered, but it obviously do not scroll.
So I'm replacing fixed
with scroll
:bg {background:url(bg.jpg) no-repeat center top scroll; }
but than image is not centered - it starts displaying from top-left corner, so that in smaller resolutions you can see left margin, which shouldn't be visible.
Here is example on jsfiddle.net. Play with background-attachment
values scroll
/fixed
and try to reduce size of result window and you will hopefully understand know what I mean.
Can you help me with solving this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用如下所示的
background-attachment
属性Try using the
background-attachment
property like below使用媒体查询。像这样的东西。
Use media queries. Something like this.