CSS 将图像置于页面顶部

发布于 2024-09-02 01:17:00 字数 383 浏览 6 评论 0原文

我需要在 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: 似乎对网站的结果没有影响。任何帮助表示赞赏。

I need to have an image at the top-center of a web page in css. Now, Im just using the background-image: in css but this puts it at the middle of the page.

Here's my code:

body {
  background-image: url("theimageurlgoeshere"); //The image is 842 x 508
  background-attachment:fixed;
  background-position: center top;
  background-repeat: no-repeat;
}

Also, Changing the background-position: seems to have no effect on the outcome of the site. Any help is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

最冷一天 2024-09-09 01:17:00

将这些值的排列从 center top 更改为 top center

background-position: top center;

在 Safari 4、Chrome 和 FF 3.5 中测试

我在测试中使用的代码是:

 body { background: url(./image.png) no-repeat top center; }

Change the arrangement of these values from center top to top center

background-position: top center;

Tested in Safari 4, Chrome, and FF 3.5

The code I used in testing was:

 body { background: url(./image.png) no-repeat top center; }
可可 2024-09-09 01:17:00

如果你想把它写在一行上:

body {
  background: url('path') center top fixed no-repeat;
}

更多信息:http://www.w3schools.com/css/pr_background-position.asp

And if you want it on a single line:

body {
  background: url('path') center top fixed no-repeat;
}

More info: http://www.w3schools.com/css/pr_background-position.asp

心的憧憬 2024-09-09 01:17:00

如果这不起作用。做保证金:0自动;

If this dosen't work. Do margin:0 auto;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文