css-sprite icon indicating copy to clipboard operation
css-sprite copied to clipboard

Sprite for :hover states?

Open sahibalejandro opened this issue 9 years ago • 9 comments

Is there an option or something to generate :hover states for the sprites?

for example, having button.png and button-hover.png generates css:

.icon { ... }
.icon-button {
  background-position: ...
  ...
}
.icon-button:hover {
  background-position: ...
}

Compass sprite generator has this feature :(

sahibalejandro avatar Apr 08 '15 21:04 sahibalejandro

You can use a template to setup your own output.

alexkaraman85 avatar Apr 12 '15 05:04 alexkaraman85

Mustache is "logic-less", this can't be done only using basic template tags, it needs an if with some RegExp validation to detect the -hover suffix on the image name and then generate the :hover styles.

Any ideas?

sahibalejandro avatar Apr 13 '15 05:04 sahibalejandro

Hopefully you can wait a few more days. In css-sprite 1.0 handlebars is used to generate the style. This will give much more flexibility. So creating a hover style can be achieved more easily. I just need a few more days to finish up all the changes.

aslansky avatar Apr 13 '15 09:04 aslansky

Thank you, I'm tuned.

sahibalejandro avatar Apr 19 '15 00:04 sahibalejandro

i need this。

gulp.spritesmith do like this:

sprites: {
  src: srcAssets + '/images/sprites/icon/*.png',
  dest: {
    css: srcAssets + '/scss/base/',
    image: srcAssets + '/images/sprites/'
  },
  options: {
    cssName: '_sprites.scss',
    cssFormat: 'css',
    cssOpts: {
      cssClass: function (item) {
        // If this is a hover sprite, name it as a hover one (e.g. 'home-hover' -> 'home:hover')
        if (item.name.indexOf('-hover') !== -1) {
          return '.icon-' + item.name.replace('-hover', ':hover');
          // Otherwise, use the name as the selector (e.g. 'home' -> 'home')
        } else {
          return '.icon-' + item.name;
        }
      }
    },
    imgName: 'icon-sprite.png',
    imgPath: '/assets/images/sprites/icon-sprite.png'
  }
}

ghostcode avatar Apr 21 '15 23:04 ghostcode

css-sprite 1.0.0 is out ... it's called sprity. it now uses handlebars as the template language. So more logic is possible whithin the templates. If this is not enough, have a look at How to write a sprity style processor. Let me know if you need more information ...

aslansky avatar May 13 '15 11:05 aslansky

Thanks, I will check it. On May 13, 2015 6:40 AM, "Alexander Slansky" [email protected] wrote:

css-sprite 1.0.0 is out ... it's called sprity https://github.com/sprity/sprity. it now uses handlebars as the template language. So more logic is possible whithin the templates. If this is not enough, have a look at How to write a sprity style processor https://github.com/sprity/sprity/wiki/How-to-write-a-sprity-style-processor. Let me know if you need more information ...

— Reply to this email directly or view it on GitHub https://github.com/aslansky/css-sprite/issues/65#issuecomment-101636224.

sahibalejandro avatar May 13 '15 13:05 sahibalejandro

Did you ever succeed in doing this?

trisys3 avatar Jan 22 '16 21:01 trisys3

Using sprite smith, yes.

sahibalejandro avatar Feb 03 '16 17:02 sahibalejandro