responsive sprites / percentages

前端 未结 9 810
天涯浪人
天涯浪人 2020-12-04 09:54

I\'ve read every single question about responsive sprites using css, I saw jsfiddle with working examples of responsive sprites, but I still cannot understand how to get the

9条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-04 10:34

    The div dimension doesn't play in the calculus, only the background sizes, and the part that you are going to use.

    Lets say that your background has a width of 1000px and a height of 500px.

    The image that you are going to use has 80px width and height.

    background-size:

    x part     1000px / 80px = 12.5   ->> 1250%
    y part      500px / 80px = 6.25   ->>  625%
    
    background-size: 1250% 625%;
    

    background-position:

    x-part     173px / 1000px = 0.173   ->> 17.3%
    y part     293px / 500px = 0.586    ->> 58.6%
    
    background-position: 17.3% 58.6%;
    

提交回复
热议问题