&l"> Scale CSS sprites to background images: a guide-PHP Chinese Network Q&A
Scale CSS sprites to background images: a guide
P粉063862561
P粉063862561 2023-11-02 10:39:28
0
2
661


.my-sprite { background-image: url("https://i.stack.imgur.com/lJpW8.png"); height: 100px; width: 100px; background-position: 0 0; background-position: -200px 0px; }


I can't get my sprite to scale to a smaller size. I want it to be like half the actual size i.e. 100x100px How can I scale it using thebackground-sizeproperty? Now it only shows the full image size of 100x100px...

P粉063862561
P粉063862561

reply all (2)
P粉594941301

You can usetransform:scale().

.my-sprite { background-image: url("https://picsum.photos/id/217/200/300"); height: 100px; width: 100px; background-position: -200px 0px; transform: scale(.3); }
    P粉864594965

    The dimensions of your image sprite are 500x400, so if you want to reduce thebackground-sizeby 2, define half that size and then adjust thebackground-positionto get Any icon you want:

    .my-sprite { background-image: url("https://i.stack.imgur.com/lJpW8.png"); height:50px; width:50px; background-position:150px 0px; background-size:250px 200px; border:1px solid; }
      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!