如何为背景图像添加边距?

时间:2011-01-14 17:49:46

标签: css

我想为背景图像添加一个边距,以便我将其与屏幕中间区域对齐,但是在该类中添加它会为整个身体添加边距。

body.poppage {
    background: url(/Imagenes/tip3.png) 50% 200px no-repeat #E2E4E9;
}

我怎么能这样做?感谢

6 个答案:

答案 0 :(得分:9)

您可以使用background-position属性

答案 1 :(得分:3)

使用容器填充为背景制作一种边距。

<div class="thebox">
    <p>HEY!</p>
</div>

div.thebox
{
box-sizing: border-box;
width:400px;
height:400px;

border: 2px solid #000000;
padding: 10px;

background: url(http://studio-creator.com/blog/public/html5.jpg) center;
background-size: contain;
background-repeat: no-repeat;
background-origin: content-box;
}

https://jsfiddle.net/gann1pwm/

答案 2 :(得分:1)

您可能想尝试别的东西......比如将图像移动到下一个孩子。您可以在固定宽度div周围创建一个包装器div来完成此任务。

答案 3 :(得分:1)

您无法真正为背景图像添加边距,因为它实际上并不是一个元素。你可能会尝试几件事:

  1. 如果您在正文中有一个包含元素,则可以将背景图像应用于此元素并在其上设置边距。

  2. 如果你想要的是让背景图像在其容器中浮动,请设置其背景位置。

答案 4 :(得分:1)

这项工作对我来说我有50px导航栏

<span>

答案 5 :(得分:0)

您可以使用此添加边距(种类)

background-position-y

对于 y 轴(margin-y)和

background-position-x

对于 x 轴 (margin-x)

如果你使用它仍然是实验性的,请谨慎

我的 Instagram @deanpi_@alfarisi.milham

相关问题