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.

Hover effect on icons

See original GitHub issue

Is it possible to build sprite with :hover pseudo-class in css? For example:

The icon folder contains icons for normal state and hover state:

icns
    ├── print.png
    └── print_hover.png

gulp task

var pngSprite = require('gulp.spritesmith');
gulp.task('sprite-png', function () {
    return gulp.src('./icons')
        .pipe(pngSprite({
            imgName: 'sprite.png',
            cssName: 'sprite.css',
            // this is what I want
            hoverImageName: function (name) {
               return name + '_hover';
            }
        }))
        .pipe(gulp.dest('./sprite'));
});

I am expecting to see something like this in css file

.icons-print {                                                                                                                                                                                              
  background-image: url(./sprites/sprite.png);                                                                                                                                                      
  background-position: -734px -618px;                                                                                                                                                                              
  width: 16px;                                                                                                                                                                                                     
  height: 16px;                                                                                                                                                                                                    
}                                                                                                                                                                                                                  
.icns-print:hover {                                                                                                                                                                                           
  background-image: url(./sprites/sprite.png);                                                                                                                                                      
  background-position: -683px -618px;                                                                                                                                                                              
  width: 16px;                                                                                                                                                                                                     
  height: 16px;                                                                                                                                                                                                    
}            

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Andrew-Dyachenkocommented, Sep 24, 2015

Unfortunatly propery: cssClass, is deprecated in 3.0.0 version of grunt-spritesmith, now use property: cssSelector instead. My code finally has worked after some edit:

sprite: {
    all: {
        src: 'assets/images/sprite/*.*',
        dest: 'dist/images/sprite/sprite.png',
        cssFormat: 'css',
        destCss: 'dist/css/sprite.css',
        cssOpts: {
            cssSelector: 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;
                }
            }
        }
    }
}
1reaction
twolfsoncommented, Mar 13, 2015

For non-CSS templates, you can leverage the provided sprite mixin. Here is an example for SCSS:

.icon-email {
  @include sprite($icon-email);

  &:hover {
    @include sprite($icon-email-hover);
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create icon hover effect using CSS ? - GeeksforGeeks
How to create icon hover effect using CSS ? · 1: All the anchor tags are targeted with the CSS declarations (within the...
Read more >
Simple Icon Hover Effects with CSS Transitions and Animations
Icon Hover Effects Simple hover effects for circular icons.
Read more >
4 Awesome icons hover effect using only HTML & CSS
4 Awesome icons hover effect using only HTML & CSS ; ◘ Like our page : https://www.facebook.com/darkcode0/ ; ◘ Paypal donation link :...
Read more >
Hover.css - A collection of CSS3 powered hover effects
All Hover.css effects make use of a single element (with the help of some pseudo-elements where necessary), are self contained so you can...
Read more >
Glowing Icon Hover Effect - CodePen
Adding Classes. In CodePen, whatever you write in the HTML editor is what goes within the <body> tags in a basic HTML5 template....
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