HTML background image offset by x pixels from the center

后端 未结 9 1373

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条回答
  •  误落风尘
    2020-12-23 09:25

    Using background-position: center; is the same as background-position: 50% 50%;.

    So you can use calc to do some simple math in CSS as a replacement for any length value, for example:

    background-position: calc(50% - 50px) 50%;
    

    Will center the background image, but shift it 50 pixels to the left.

提交回复
热议问题