How to shift a background image with css

自古美人都是妖i 提交于 2019-11-30 08:07:40

You can use the background-position:

background-position: 8px 8px;
schubySteve

you could also use some short hand.
background: <colour> <image url> <repeat> <left> <top> <scroll>

for yours i'd be thinking something like:
background : transparent url(<location to img>) no-repeat 8px 8px scroll;

Rather than manually shifting the image by 8px, you should just anchor the image to the padding box (green in the diagram below) instead of the border box (yellow). Doing this will place the top-left corner of the image inside of the border instead of behind it.

background-origin: padding-box;

This will make maintenance easier since it will still work even if you change the border width.

You can also set the background's origin to the content box (blue):

background-origin: content-box;

Documentation / Simple Demo @ MDN

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!