【问题标题】:Add margin on top of the background image在背景图像顶部添加边距
【发布时间】:2016-05-27 03:04:05
【问题描述】:

我想在背景图片上添加边距。这是我的背景图片 css 代码

body {
  background-image:url(Images/Home.png);
  background-position:top;
  background-repeat:no-repeat;
  background-attachment:fixed;
}

我尝试在 css 正文代码中添加 margin-top:10px;,但它不起作用。只有div的移动

【问题讨论】:

  • 哪个div?您只是在修改body

标签: html css background-image margin padding


【解决方案1】:

这将使背景图像从顶部偏移 10 个像素:

background-position: top 10px;

【讨论】:

  • 试过了,不行,背景图向左移动了
【解决方案2】:

你可以在body之前添加一个div,设置它的高度为10px。应该给你你正在寻找的间距。

【讨论】:

    【解决方案3】:

    下面的而不是你的背景位置怎么样?

    background-position:0px 10px;
    

    【讨论】:

    • 成功了!不幸的是,背景图像向左改变位置。你知道如何解决吗?我尝试将位置设置为中心,也不起作用。
    • 背景位置:中心 10px;