gpt4 book ai didi

CSS 将图像放在页面顶部

转载 作者:太空狗 更新时间:2023-10-29 12:29:38 26 4
gpt4 key购买 nike

我需要在 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/

26 4 0
文章推荐: python - 抓取键盘输出
文章推荐: html - 为什么

里面不允许