我认为答案是否定的,但是你可以用CSS定位一个背景图像,这样它就离右边有一个固定数量的像素?
如果我设置x和y的背景位置值,似乎它们只分别从左边和上面给出固定的像素调整。
我认为答案是否定的,但是你可以用CSS定位一个背景图像,这样它就离右边有一个固定数量的像素?
如果我设置x和y的背景位置值,似乎它们只分别从左边和上面给出固定的像素调整。
当前回答
可以使用属性边框作为从右边开始的长度
background: url('/img.png') no-repeat right center;
border-right: 10px solid transparent;
其他回答
据我所知,CSS规范并没有提供您所要求的内容,当然,除了CSS表达式之外。除去你不想使用表达式或Javascript的假设,我看到了三个hack的解决方案:
Make sure your background image matches the size of the container (at least in width) and set background-repeat: repeat or repeat-x if only the width is equalized. Then, having something appear x pixels from the right is as simple as background-position: -5px 0px. Using percentages for background-position exhibits special behaviour that is better seen than described here. Give it a shot. Essentially, background-position: 90% 50% will make the right edge of the background image line up 10% away from the right edge of the container. Create a div containing the image. Explicitly set the position of the containing element position: relative if not already set. Set the image container to position: absolute; right: 10px; top: 10px;, obviously adjusting the final two as you see fit. Place the image div container into the containing element.
适用于所有真正的浏览器(以及IE9+):
background-position: right 10px top 10px;
我用它来RTL WordPress主题。 看例子:临时网站或真正的网站将很快上线。 看看大DIVs右下角的图标。
试试这个:
#myelement {
background-position: 100% 50%;
margin-right: 5px;
}
注意上面的代码会将整个元素(不仅仅是背景图像)向右移动5px。这对你的案子来说可能没问题。
可以使用属性边框作为从右边开始的长度
background: url('/img.png') no-repeat right center;
border-right: 10px solid transparent;
这在Chrome 27中工作,我不知道它是否有效,也不知道其他浏览器能做什么。我对此感到很惊讶。
background: url(../img/icon_file_upload.png) top+3px right+10px no-repeat;