我需要在 CSS 网页的顶部中心放置一个图像。现在,我只是在 css 中使用 background-image:
但这会将它放在页面的中间。
这是我的代码:
body {
background-image: url("theimageurlgoeshere"); //The image is 842 x 508
background-attachment:fixed;
background-position: center top;
background-repeat: no-repeat;
}
此外,更改 background-position:
似乎对网站的结果没有影响。感谢您的帮助。
最佳答案
将这些值的排列从 center top
更改为 top center
background-position: top center;
在 Safari 4、Chrome 和 FF 3.5 中测试
我在测试中使用的代码是:
body { background: url(./image.png) no-repeat top center; }
关于CSS 将图像放在页面顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2878633/