How does sass position the sprite loop?

I have such a sprite picture

clipboard.png

css

clipboard.png

here is a portion of css Code

.icon-item:nth-child(1) {
    background-position: -8px 0;
}
.icon-item:nth-child(2) {
    background-position: -95px 0;
}
.icon-item:nth-child(3) {
    background-position: -182px 0;
}
.icon-item:nth-child(4) {
    background-position: -269px 0;
}
.icon-item:nth-child(5) {
    background-position: -8px -70px;
}
.icon-item:nth-child(6) {
    background-position: -95px -70px;
}
.icon-item:nth-child(7) {
    background-position: -182px -70px;
}
.icon-item:nth-child(8) {
    background-position: -269px -70px;
}
The

css code has a lot in common, only the indexes and coordinates are changed, and it looks a little redundant. I have recently come into contact with sass and want to implement it in a loop.

how to change an effect like this?

$for $i from 1 through 8 {
    .icon-item:nth-child(-sharp{$i}) {
        background-position: ......
        }
}
Mar.21,2021

since they all use scss. Isn't the correct use of automatic sprite


compass has an automatic sprite function. Each icon will generate a class for you. Just bring it to you and use it

.
Menu