HTML background image offset by x pixels from the center

后端 未结 9 1364

I\'d like to put an image as the background of a webpage but have it offset by some number of pixels with respect to the center.

How can I do this?

I want:

9条回答
  •  Happy的楠姐
    2020-12-23 09:22

    the units need to be the same, so when specifying pixels for the x-position, the y-position needs to be also in pixels.

    example:

    background-position: 25% 50%;
    

    EDIT: I just re-read your query and the only way to do that is either knowing the absolute position (assuming the outer elements aren't dynamic/flexible), or in case you don't know the position, maybe use javascript to set its position.

提交回复
热议问题