向背景图像添加左边距或右边距

问题描述 投票:2回答:3

我试图从左或右给出背景图像空间。

正如您在该图片中看到的那样,第一个扇区很好,背景图像左侧有空间,内容块就是我想要的。

第二个扇区应该是相反的,内容块右边是左边的图像。

我解决了这个问题:

background: url(/bilder/2.jpg);
background-position-x: 300px;
background-repeat: no-repeat;
background-size: cover;

对于第一个块,但对于第二个块,这个CSS不起作用

background: url(/bilder/2.jpg);
background-position-x: -300px;
background-repeat: no-repeat;
background-size: cover;

是否有可能给背景图像margin-leftmargin-right

html css3 background-image
3个回答
1
投票

您可以移动背景图像。例:

background-position: right 20px bottom: 10px;

也许你应该告诉我们你的HTML代码。


0
投票

background-position-x测量距左边界的距离,因此你应该使用background-position-x: 20px;(大约)作为第二张图像。

但我不会在这里使用background-size: cover(它真的涵盖整个元素/ div),我想知道你是否真的在你发布的图像页面上使用过它?


0
投票

谢谢你的第一个想法,我玩了一下,认为我解决了另一个问题

Demo Page here

如你所见,图片布局很好(在大屏幕上),但现在,我怎样才能获得图片的位置。在第2部分中,我可以看到图像的右侧部分,而骑车人则位于图片的左侧部分。

© www.soinside.com 2019 - 2024. All rights reserved.