background-size with background-position doesn't scale the position?

前端 未结 6 1662
轮回少年
轮回少年 2021-02-05 13:16

I\'ve a sprite of 62 images of 91 * 91px, which makes the whole thing 91 * 5642 px. They\'re displayed in sort of a dynamic grid that grows and shrinks depending on user/pointer

6条回答
  •  逝去的感伤
    2021-02-05 13:53

    Well ..., you have several problems. ;-)
    Inline styles are "bad" in all ways. One is that you cannot override them with any external CSS (cause of their higher specificity). So this already one reason why there is no pure CSS solution for your problem.

    Another reason is, that you would need to re-calculate the background-position depending on the actual position, respectively on the sprite number. Something you cannot do with CSS, yet (e.g. something like: background position: 0 calc(nth-child * 91px);)

    So the only pure CCS way will be using the sale transform which also fairly good supported!

    BTW: "How the sprite looks is up to me, so I could make it have a 120 * 120 grid instead of 91 * 91, if that would be simpler..."
    That would be better at least. Downscaling is always better quality than upscaling!

    A Javascript solution, especially with jQuery is quite simple on the opposite, as you can use the .index() function and so easily calculate the new background-position.

    Conclusion:
    At the moment there is no real/ practical solution for handling CSS sprites in such a way!

提交回复
热议问题