Can spritesmith generate responsive sprites?
See original GitHub issueResponsive sprites means they scale with the browser, and also, that you can make an image fit its container, etc.
Does spritesmith already generate this sort of data? Has anyone done this, any tips?
The typical calculation is:
width: @image-width;
height: @image-height;
background-size: ((@sprite-total-width / @image-width) * 100%)
((@sprite-total-height / @image-height) * 100%);
// x or y may be 0% depending on stacking of the sprite (vertical vs horizontal)
background-position: ((@image-offset-x / (@sprite-total-width - @image-width)) * 100%)
((@image-offset-y / (@sprite-total-height - @image-height)) * 100%);
There is some background here and here.
It’s fiddly, and I need to do it all by hand. Has anyone managed to do something like this with less and spritesmith?
Issue Analytics
- State:
- Created 9 years ago
- Comments:11 (3 by maintainers)
Top Results From Across the Web
How do I make the sprite images generated by webpack ...
When using webpack-spritesmith to generate a sprite image, the css generated typically looks like this: .icon-AutoFollow { background-image: ...
Read more >spritesmith - npm
Utility that takes images and creates a spritesheet with JSON sprite data. Latest version: 3.4.0, last published: 3 years ago.
Read more >Gulp.spritesmith-multi - npm.io
A wrapper for gulp.spritesmith to generate multiple sprites and stylesheets. ... You can continue the pipeline the way the original gulp.spritesmith support ...
Read more >Responsive CSS sprites by lorenzomarcon.com
This approach works and is widely used today, but the problem is that it's not responsive. Sprites (and so tiles) generated this way...
Read more >Automating CSS Sprites for Large Organisations
A CSS sprite is the technique of combining multiple images into a single… ... With this new sprite process in place, we can...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It is 2016, background-size CSS3 property is well supported and responsive websites are the norm. If you must support the 0.3% of users who are still using IE8, then don’t use this version.
Thanks to @stevenw00 and @denisz1 for leading the way on this.
https://gist.github.com/jasonlav/32e72a4afc348cd176dcd52cf9a45dbe
@stevenw00 thanks for that scss solution. I made a couple tweaks: https://gist.github.com/kevinmpowell/97357409b9af7625b257
I had an existing CSS role
max-width: 100%;
on all my images which was breaking this functionality so I explicitly set that tomax-width: none;
The margin-bottom calculation was incorrect. I think it would work if your sprite was one horizontal strip, but mine wasn’t so I was seeing issues. My fork made the change.