十分钟后,出于某种原因我已经不知所措,非常感谢任何帮助。我有一个正在尝试编码的布局,参见 here .基本上我希望背景图像(咖啡 bean )在您向下滚动页面时保持固定。但是,主要内容不想居中,背景图片也不想固定。无论我做什么,主体要么最终向左而不是居中对齐,要么背景图像被搞砸了。任何能为我指明正确方向的人都是英雄!到目前为止的页面可以看到here .
html, body {
background-color: #e0dac8;
}
#content {
background-image: url(IMG/bg_head.jpg);
background-color: #e0dac8;
background-repeat: no-repeat;
background-position: center top;
margin: 0px;
padding: 0px;
position: absolute;
}
#wrapper {
margin: auto;
height: auto;
width: auto;
最佳答案
是你想要的吗? http://jsfiddle.net/LRxpA/embedded/result/
我删除了绝对位置并使用“margin: 0 auto;”居中#content,然后使用“background-attachment: fixed;”修复了背景。
关于css - 绝对位置噩梦 - 甚至无法将主要内容置于全身背景的中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8126011/