2

Im using gulp-svg-sprite https://github.com/jkphl/gulp-svg-sprite

Is it possible to use the same icon at different sizes? Prior to spriting this was easy and in fact was one of the things I like most about SVGs:

http://codepen.io/anon/pen/qZQvYN

.icon-small,
.icon-large {
    background-image: url(https://lincolnloop.com/static/assets/img/lincolnloop-mark.9b93136b4561.svg);
    background-size: 100% 100%;
}

.icon-small {
    width: 50px;
    height: 50px;
}

.icon-large {
    width: 100px;
    height: 100px;
}

However now that I'm using a sprite I cant use this solution as the background-size comes from the mixin. Even if I overwrote this then the background-position would be made wrong.

http://codepen.io/anon/pen/JXezaK

.icon-small,
.icon-large {
    background-image: url(https://scotthsmith.com/projects/social-icons/blue/IconGrid.svg?v1.11);
  background-size: auto 400px;
  border: 1px solid grey;
}

.icon-small {
    width: 50px;
    height: 50px;
}

.icon-large {
    width: 100px;
    height: 100px;
}
Evanss
  • 23,390
  • 94
  • 282
  • 505

2 Answers2

1

I suppose you don't have text on your svg. Then using transform: scale(2) should fix it:

.icon-large {
  width: 50px;
  height: 50px;
  transform: scale(2)
}

This SO question seem to be discussing similar issue.

Community
  • 1
  • 1
Thoran
  • 8,884
  • 7
  • 41
  • 50
0

The other option is to specify your width and height in ems, and then use font-size to scale your icon.

More information can be read on this blog post: https://www.liquidlight.co.uk/blog/article/creating-svg-sprites-using-gulp-and-sass/

mikestreety
  • 833
  • 6
  • 28