question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can spritesmith generate responsive sprites?

See original GitHub issue

Responsive 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:closed
  • Created 9 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
jasonlavcommented, Sep 14, 2016

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

0reactions
kevinmpowellcommented, Jul 6, 2015

@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 to max-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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found