将css背景向右对齐

将css背景向右对齐,css,background,background-position,Css,Background,Background Position,我想把div背景改到右边 我有一些css类使用背景位置:x,y css代码: .menu, .bg1, .bg2 { background-image:url(bg.png); background-repeat: no-repeat; padding-left: 50px; } .bg1 { background-position: 0px 5px; } .bg2 { background-position: 0px 15px; } 我只想在右边显示填

我想把div背景改到右边

我有一些css类使用背景位置:x,y

css代码:

.menu, .bg1, .bg2 {
    background-image:url(bg.png);
    background-repeat: no-repeat;
    padding-left: 50px;
}
.bg1 {
    background-position: 0px 5px;
}
.bg2 {
    background-position: 0px 15px;
}
我只想在右边显示填充和背景

padding-right: 50px;
如何将背景位置移动到右侧而不需要更改x、y位置,只需将其与右侧对齐


jsidle:

添加
位置:相对
右侧:0px
使用
背景位置

可以对图像进行如下声明:

background-position: center right;
这里,第一个值是水平的,第二个值是垂直的

编辑

看到你拉小提琴后,我想到了这个解决方案:

您需要更改
背景位置的第一个值,使其刚好向右:

.bg1 {
  background-position: 100% 0px;
}

听起来您可能试图保持图像从右侧偏移。如果是这样的话,您可以使用来进行背景定位,也可以使用。

我想将div背景更改为右侧
您知道这不太容易理解吗?@RokoC.Bulijan我刚刚编辑了它,因为您发布了…我想将背景向右移动,而不更改bg1和bg2背景位置,现在它在左边显示背景,但我想在右边显示。当我将背景位置添加到主类的右侧时,bg1和bg2不显示所选位置并显示在外部。希望你能理解!不明白,加一把小提琴什么的。。。你希望如何在不改变背景位置的情况下移动背景?像这样?告诉我,我把它作为一个答案贴出来。他已经这样做了,他说他想在不改变原始背景位置属性的情况下将背景移到右边。。。我想。。。这个问题有点难理解。他说不要改变x,y的位置,我猜他指的是固定值。请你创建一堆代码,因为我觉得你的问题有点混乱