Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9130757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:01:12+00:00 2026-06-17T08:01:12+00:00

I am using compass to generate sprite images. And I have MANY sprite icons,

  • 0

I am using compass to generate sprite images. And I have MANY sprite icons, and it is generating too much CSS code (too many class selectors for the background image). So lets analyze the compass sprite code:

as you can see here http://compass-style.org/help/tutorials/spriting/

@import "my-icons/*.png";
@include all-my-icons-sprites;

Will generate:

.my-icons-sprite,
.my-icons-delete,
.my-icons-edit,
.my-icons-new,
.my-icons-save   { background: url('/images/my-icons-s34fe0604ab.png') no-repeat; }

.my-icons-delete { background-position: 0 0; }
.my-icons-edit   { background-position: 0 -32px; }
.my-icons-new    { background-position: 0 -64px; }
.my-icons-save   { background-position: 0 -96px; }

If you see I use this way: <div class="my-icons-sprite my-icons-delete"></div>

I want Compass to generate this code:

.my-icons-sprite { background: url('/images/my-icons-s34fe0604ab.png') no-repeat; }

.my-icons-delete { background-position: 0 0; }
.my-icons-edit   { background-position: 0 -32px; }
.my-icons-new    { background-position: 0 -64px; }
.my-icons-save   { background-position: 0 -96px; }

Else each new image, it’ll add for background and background position. Causing too many selectors.

Is there a configuration for that?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:01:13+00:00Added an answer on June 17, 2026 at 8:01 am

    Have you tried this snippet for Compass?

    $icons: sprite-map("icons/*.png");
    
    i{
        background: $icons;
        display: inline-block; // or block
    }
    
    @each $i in sprite_names($icons){
        .icn-#{$i}{
            background-position: sprite-position($icons, $i);
            @include sprite-dimensions($icons, $i);
        }
    }
    

    This example uses the <i></i>-tag with a class containing the prefix icn- combined with the filename of the separate .png-files in your icons-folder. Like this:

    <i class="icn-delete"></i>
    

    The generated CSS looks like this:

    i {
        background: url('/path/to/generated/spritemap/my-icons-xxxxxxxxxxx.png');
        display: inline-block;
    }
    .icn-delete {
         background-position: 0 0;
         height: 32px; // assuming the width is 32px
         width: 32px; // assuming the height is 32px
    }
    .icn-edit{
         background-position: 0 -32px;
         height: 32px; // assuming the width is 32px
         width: 32px; // assuming the height is 32px
    }
    .icn-new {
         background-position: 0 -64px;
         height: 32px; // assuming the width is 32px
         width: 32px; // assuming the height is 32px
    }
    ...
    ..
    .
    

    Still, I haven’t quite figured out how to use this in combination with Compass’ Magic Selectors.

    Magic Selectors works very nice when you need different states (:hover, :active, :target). All you have to do is name your files like this: filename_state.png (delete_hover.png, delete_active.png etc). Compass’ Magic Selectors then automatically generates css for :hover, :active and :target (delete:hover, delete_hover and delete-hover). This way you are quite free to choose how you would represent a state-change.

    If you, in my first example, has filenames with the postfix for hover/ active states, the snippet only writes CSS like this:

    .icn-edit_hover {
        background-position: -32px -32px;
        height: 32px;
        width: 32px;
    }
    

    I’d really like to have it print this:

    .icn-edit:hover, .icn-edit_hover, .icn-edit-hover{
        background-position: 0 -32px;
        height: 32px;
        width: 32px;
    }
    

    like the traditional Compass’ Magic Selectors does. Any idea?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Compass (a CSS Framework) to generate sprite images. It work, but compass
Now if we generate sprite image using compass @import imgs/*.png; @include all-imgs-sprites; we ill
Is there a way to get compass to generate a sprite sheet from images
Using a CSS image sprite, I'm creating an 'interactive' image where hovering over certain
I've been using compass from http://compass-style.org/ to manage my sites css for a long
I am using compass to produce my CSS stylesheets. In my style sheets, I
I have a site running on Heroku using Compass with Saas an is working
I am using blueprint via Compass but have no scroll bars on longer pages,
I'm using sass and compass and I am trying to create css classes for
I have a problem using compass-style remotley over ssh and my favorite text-editor textmate.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.